When you use Excel in ASP.net, you first need to set permissions on the COM component. If permissions are not set, the access denied error is reported. Detailed error messages are usually as follows:
Note: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace for more information about the error and where the error occurred in the code.
Exception Details: system.unauthorizedaccessexception: Access denied.
ASP.net is not authorized to access the requested resource. Consider granting the ASP.NET request identity access to this resource. ASP.net has a base process identity that is used when the application has no impersonation (typically, on IIS 5, on IIS 6 for network services). If the application is being emulated, the identity will be anonymous (typically IUSR_machinename) or authenticated request users.
To grant ASP.net write access to a file, right-click the file in Explorer, select Properties, and then select the Security tab. Click Add to add the appropriate user or group. Highlight the ASP.net account, and select the box that corresponds to the required access rights.
The way to set permissions is to enter DCOMCNFG in the Windows Run box and turn on COM management. In the security of Excel applications, add access, run, and configure permissions for users such as ASPNET, Iuser, IWAM, and so on.