Issues with operating permissions for Office COM components such as word,excel in ASP.

Source: Internet
Author: User
Tags stack trace

Recently in the opening of the original write a Web program run, there is an Excel operation permissions, specifically, in the code to call the following paragraph of the Excel operation related statements,
Application Curexcelapp = new ApplicationClass ();

Prompt permission is insufficient, the specific prompt content is as follows:

Failed to retrieve a component of the CLSID {00024500-0000-0000-c000-000000000046} in a COM class factory because of the following error: 80070005.

Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code. Exception Details: System. UnauthorizedAccessException: Failed to retrieve a component of the CLSID {00024500-0000-0000-c000-000000000046} in a COM class factory because of the following error: 80070005. ASP. NET is not authorized to access the requested resource. Consider granting an ASP. NET request to identify permissions to access this resource. ASP. NET has a base process identity that is used when the application does not impersonate (typically, {machine}aspnet on IIS 5, and Network Service on IIS 6). If the application is impersonating by <identity impersonate= "true"/>, the identity will be the anonymous user (typically IUSR_machinename) or the authenticated requesting user. To grant ASP. NET access permission to a file, in Explorer, right-click the file, select Properties, and then select the Security tab. Click Add to add the appropriate user or group. Highlight the ASP, and select the box that corresponds to the required access. SOURCE Error: Line 533://Create Excel Information

Line 534:object missing = System. Reflection.Missing.Value;

Line 535:application Curexcelapp = new ApplicationClass ();

Line 536:curexcelapp.application.displayalerts = false;

Line 537:workbook Curworkbook = CUREXCELAPP.WORKBOOKS.ADD (Xlwbatemplate.xlwbatworksheet);

Originally encountered this situation, know that the DCOM component of Excel due to insufficient permissions, so follow the original steps to set up, as follows:

1: Excel software that installs Office on the server;

2: Enter Dcomcnfg.exe start "Component Services" in "Start", "Run";

3: Double-click "Computer", "Component Services", "My Computer", "DCOM Configuration";

4: Find "Microsoft Excel application" in "DCOM Config", right click on it, then click "Properties" to pop Up "Microsoft Excel application Properties" dialog box;

5: Click on the "Logo" tab and select "Interactive User";

6: Click on the "Security" tab, click "Customize" on "Launch and Activation Permissions", then click on the corresponding "edit" button, add a "NETWORK SERVICE" user in the "Security" dialog box (note To select this computer name) and give it "local launch" and "Local activation" Permissions. Add the ASPNET user to the XP system and the 2000 system;

7: Remain the "Security" tab, click "Customize" on "Access", then click "Edit" and add a "NETWORK SERVICE" user to the "Security" dialog box that appears, then give "Local access" permission.

Note: The 5th step is required, otherwise the following error will occur:

There is not enough memory or disk space for Microsoft Office Excel to open or save any documents again. To get more available memory, close the workbook or program you're no longer using. To free up disk space, delete the files that are not needed on the appropriate disk.

Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code. Exception Details: system.Runtime.InteropServices.COMException: There is not enough memory or disk space for Microsoft Office Excel to open or save any documents again. To get more available memory, close the workbook or program you're no longer using. To free up disk space, delete the files that are not needed on the appropriate disk. SOURCE Error:

Line 535:application Curexcelapp = new ApplicationClass ();

Line 536:curexcelapp.application.displayalerts = false;

Line 537:workbook Curworkbook = CUREXCELAPP.WORKBOOKS.ADD (Xlwbatemplate.xlwbatworksheet);

Line 538:worksheet Curworksheet = (Worksheet) curWorkBook.Sheets.get_Item (1);

Line 539:

After the above steps have been set up, re-execute the program, or the issue of insufficient permissions, the problem does not know where to appear, careful analysis of the information and code, finally found the problem, originally in Web. config, the following settings:

<identity impersonate= "true"/>

The purpose of this paragraph is to do a client-side impersonation for each request, as explained in the prompt message, because there is no set username, the currently executing user is IUSR_machinename, and the user is not authorized to manipulate the Excel component, in order to verify that the analysis is correct, A bit of validation was performed:

Delete this sentence, execute the procedure, everything is normal;

Add the currently logged-in user to the Excel operation permission, and make the following settings: <identity impersonate= "true" username= "* * *" password= "* * *"/&GT;, execute the program, everything is OK;

Add all the users in the Excel operation permissions and make the following settings: <identity impersonate= "true"/&GT;, executing the program, there is an insufficient permissions error.

With the above verification, we can conclude that when the client impersonation setting is not performed, the ASP. NET program calls the Excel component using the Network Service user (in XP and 2000, using the ASPNET user), using the settings <identity Impersonate= "true"/> for client impersonation, using a IUSR_machinename user, but the user does not have permission to invoke the Excel component, even if the user's relevant permissions are set; Use Settings <identity Impersonate= "true" username= "* * * * * * * * * *" password= "* * *"/> for client impersonation, the Excel component can be successfully invoked as long as the permissions of the relevant user are set. However, it is important to note that the user's password cannot be empty due to the limit of ASP.

In dealing with the problem, we found a more useful information on the Internet, and shared with you the following:

Troubleshoot deployment issues on Windows Server 2003 Excel.exe process

After the operation of Excel, each time will leave a Execl.exe process, in any case can not be closed, including garbage collection, and so on, I do not know, but the other server operating systems and XP operating system does not exist on this issue.

To solve such problems, there is a way to learn, is to kill the process of the method, but there is a certain risk, to note that the specific method is as follows:

The operation process has a certain risk, all first of all to have this kind of permission, add the permission method in the Web. Config add permissions <identity impersonate= "true" username= "login" password= "password"/>

Kill Process Method
1Publicstaticvoid KillProcess (stringprocessName)2 {3System. Diagnostics.process MyProc =NewSystem. Diagnostics.process ();//get all the open processes4 5 Try         6 {7 8 foreach(Process ThisprocinchProcess.getprocessesbyname (processName))9 Ten{if(!Thisproc. CloseMainWindow ()) One  A { -  - if(thisproc!=NULL) the  - Thisproc.           Kill ();  -  - }} +  - } +  A Catch(Exception Exc) at  -{ThrowExc; } -  -}

After Excel is done, the kill process method is called, and the next time it is called correctly

Reprinted from http://wallimn.iteye.com/blog/660322, thank you very much.

Issues with operating permissions for Office COM components such as word,excel in ASP.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.