By default, ASP. NET accounts do not have the permission to operate Microsoft Office objects. If you do not configure permissions, the code will throw an exception similar to the following:
Failed to retrieve components whose CLSID is {00024500-0000-0000-C000-000000000046} in the COM class factory because of the following error: 80070005.
This makes it difficult for Asp. NET to operate Microsoft Office objects. However, we still need to find a way to operate Office objects. The following describes the methods I have used in the development process:
Method 1: configure the Web. Config file to simulate the account of the local system during each request.
Specific Operation: Add the following nodes to the Web. Config file:
<Identity impersonate = "true" userName = "accountname" password = "password"/>
Here, userName is the local account to be simulated, and password is the password of this account.
Method 2: In "DCOM configuration", configure the Word operation permission for the IIS account (the same for other Office objects.
Specific operations: "Component Service"-> Computer-> My Computer-> DCOM Config) -> Microsoft Office Word 97-2003 documents, right-click "Microsoft Office Word 97-2003 documents", and select "properties" for two steps:
(1) On The Identity tab, select The interactive user )".
(2) On the Security tab, select "customer" for the first two groups (START and activate permissions and access permissions )", click "edit". On the displayed page, add an IIS account (the Server version of the operating system is generally network services, and other systems (XP) may be ASP. and assign all permissions to the user in the following permission box.
Method 3: assign a local account to the ASP. NET Site application pool
Specific Operation: in IIS, It is ASP. )".
In IIS7.0, follow these steps: Create a new application pool for the ASP. NET site. Select the application pool, advanced settings, process mode, and identity. Select localSystem.
Among the above three methods, I prefer the third method, because after the Word object is operated, the process of the Word object needs to be closed, and the third method can enable ASP without other settings.. NET applications have the permission to end the word process.