I have an ASP.NET 4.5 web forms app running on an IIS 7.5. I created a page where the user inputs some information and selects some stuff. At the bottom of the page I have a button that generates a word document.
How ?
I am using Microsoft Word Object Library and I have uploaded a word document template. In it I have added MergeFields which I am refering in the code behind and initializing them. This works great locally. When I uploaded the app on the server..big surprise:
Server Error in '/' Application. Retrieving the COM class factory for component with CLSID {000209FF-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 , 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.
The weird thing about it is that I have a few more files in the folder where I uploaded this word document template. Those are working fine inside the same application. I am using some excel templates. It's clearly a thing of not having access but why and how can I fix it ?
I tried to follow the instructions and right clicked on it to see the security properties. It already has the groups added and full rights assigned. Why can't it access it ? It might be good to mention here that I am using impersonation.
I would really like to know if there is a way to fix this or do I need to write all the word manipulation code using a different library ?
Thank you!