Keywords: IIS | Excel COM | Access Denied | DCOM Configuration | ASP.NET
Abstract: This article provides an in-depth analysis of the "Access Denied" error (HRESULT: 0x80070005) encountered when calling Excel COM components from ASP.NET in IIS 6.0 environments. Through systematic configuration steps including Office installation, user permission settings, DCOM security configuration, and application pool identity adjustments, it offers a complete solution. The article also explores alternatives like Open XML SDK and explains special considerations for 64-bit Windows Server environments.
Problem Background and Error Analysis
When calling Microsoft Office Excel COM components from ASP.NET web applications, developers frequently encounter the following error:
"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))
This error typically occurs in IIS 6.0 environments, particularly on Windows Server 2008 Enterprise Edition 64-bit systems. The error code 0x80070005 indicates insufficient access permissions, preventing the system from creating an instance of the Excel COM component's class factory.
Core Configuration Steps
Resolving this issue requires systematic configuration at multiple levels:
Office Runtime Installation Verification
First, ensure that a full version of Microsoft Office Professional is installed on the server. Office 2010 or newer is recommended, as newer versions provide better COM interop support. Avoid using stripped-down or runtime versions, which may lack necessary COM component registrations.
Dedicated User Account Creation
Create a dedicated user account (e.g., ExcelUser) specifically for Excel COM operations, configured with the following properties:
- Password never expires
- User cannot change password
- Add user to Administrators group to ensure sufficient privileges
Detailed DCOM Configuration Steps
Configure Excel COM component security settings through Component Services Manager:
- Open Control Panel → Administrative Tools → Component Services
- Expand Computers → My Computer → DCOM Config
- Locate and right-click Microsoft Excel Application, select Properties
- In the General tab, set Authentication Level to None
- In the Security tab, customize the following three permissions:
- Launch and Activation Permissions: Add Everyone group and grant Local Launch and Local Activation rights
- Access Permissions: Add Everyone group and grant Local Access rights
- Configuration Permissions: Add Everyone group and grant Full Control rights
- In the Identity tab, select This User, enter the previously created ExcelUser account and password
Application Pool Configuration Optimization
IIS application pool configuration is crucial for COM component access:
- Create a dedicated application pool for the application, avoiding shared pools
- Set the application pool's Identity to LocalSystem, which typically resolves permission issues
- For 32-bit Office installations on 64-bit systems, enable the Enable 32-bit Applications option
Code Implementation Example
Below is an example of properly instantiating Excel objects in ASP.NET:
using excel = Microsoft.Office.Interop.Excel.Application;
namespace TestHosting
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
excel excelObj = new Microsoft.Office.Interop.Excel.Application();
// Subsequent Excel operation code
excelObj.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelObj);
}
catch (Exception ex)
{
// Error handling logic
}
}
}
}
Alternative Solution Considerations
Given the complexity of COM interop, consider evaluating these alternatives:
- Open XML SDK: Microsoft's open-source library for manipulating Excel files without Office installation
- EPPlus: Third-party open-source library providing friendly APIs for Excel file operations
- NPOI: .NET version of POI library supporting various Office document formats
Troubleshooting and Verification
After configuration, perform the following verification steps:
- Manually launch Excel application to confirm the configured user account can run Excel normally
- Check Windows Event Viewer application logs for related error information
- Use Process Monitor tool to monitor file system and registry access, identifying permission issues
- Ensure all Excel processes are completely terminated before testing
Best Practice Recommendations
When using Excel COM components in production environments, follow these best practices:
- Run COM interop code in separate application domains
- Implement comprehensive exception handling and resource cleanup mechanisms
- Consider using background services for Excel operations to avoid impacting web request response times
- Regularly monitor server resource usage to prevent Excel process leaks