Using Microsoft.Office.Interop.Word and Excel in ASP NET Web App

 - If you are using Microsoft.Office.Interop.Word/Excel to parse to other format, it may work well in testing but will not work in real IIS server:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.


- Solve problem:

1. Install the below file in Server Computer

Microsoft Office 2010: Primary Interop Assemblies Redistributable 

from url: https://www.microsoft.com/en-us/download/details.aspx?id=3508
(https://www.microsoft.com/en-us/download/confirmation.aspx?id=3508)

2. Configure DCOM
  • Go to the Start-Run menu item.
  • Type in "DCOMCNFG" and hit enter.
  • This should load the "Component Services" MMC (you can also load from Administrative Tools - Component Services"
  • Expand "Component Services"
  • Expand "Computers"
  • Expand "My Computer"
  • Select the "DCOM Config" item
  • Select the "Microsoft Excel Application" item.
  • Right click and select Properties
  • Select the Security Tab and you should see the following:

In Launch and Activation Permissions, select Custom, the click on Edit -> Add permissions for users: IUSRIIS_IUSRS and NETWORK SERVICE with full access. (Remember select Location is the name of the computer as the same as C




Do similar with Access Permissions

https://www.ryadel.com/en/80070005-access-denied-error-accessing-word-interop-server-fix-asp-net-core-dcom/



Comments

Popular posts from this blog

ASP Net API pass parameter frombody

avoid Caching in asp net mvc