Site icon Ryadel

80070005 Access is denied error while accessing Word Interop from the Server in a ASP.NET Application - How to fix

Last week I published a couple post regarding the use of the Microsoft.Office.Interop.Word namespace within an ASP.NET C# Application, respectively about opening a DOC or DOCX file from a Byte Array and converting them to PDF files. Although these techniques can be very useful to deal with MS Word documents, they have more than a couple drawbacks that we should always take into consideration when using them:

I'm not saying we shouldn't use them: as a matter of fact we kinda have to, unless we want to donate a kidney to some commercial libraries that can handle these tasks in a much better way. At the same time, we should get ready to experience some issues because they will create some havoc here and there sooner or later.

In this post we'll be talking about the following error, which you will often see right after publishing your web application to your IIS-enabled Windows Server:

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))

As you might easily guess, this is a permissions issue related to the usage of these DCOM components we talked about earlier: let's see what we can do about it.

The first thing we should do is to acknowledge the problem. You most likely already know that the permissions given to the IUSR and IIS_IUSRS accounts - those used by IIS to serve their web applications - are very different between your development machine and a real Web Server machine: this is exactly what's been happening there. The same Interop.Word methods that flawlessly work on your PC won't perform well on a real server right out of the box. In order to make them work we need to properly configure the access permissions and launch permissions of the required DCOM components.

Here's how we can do that:

That's about it.

Wait a minute: what if there is no Microsoft Word (something) entry in the DCOM components list?

If you experience this, it most likely means that you either don't have MS Word installed on the server machine or you have installed a 32-bit version within a 64-bit environment. You can fix the former case by installing MS Word, otherwise you're doomed. If it's the latter, you hit a known bug of most Windows-based machines: the DCOM configuration manager only shows the 64-bit DCOM components. Luckily enough, you can still execute the 32-bit version by using the following command-line instruction:

Repeat the above guide using this command instead of

DCOMCNFG

and you should be good to go.

If this still doesn't work, we strongly suggest to take a look to this Technet blog post which explains a number of other possible workarounds for this specific issue.

 

*/ ?>
Exit mobile version