Solution to Asp.net Excel access rejection

Source: Internet
Author: User
Tlbimp.exe in c: \ Program Files \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin
To operate Excel in Asp.net, follow these steps:
Tlbimp excel.exe generates excel. dll and copies excel. DLL to wwwroot \ bin. This grants the strong execution permission for the IIS directory. And excel. dll can be written.
Part Code As follows:
Excel. applicationclass test = new excel. applicationclass ();
Test. Visible = true;
Excel. workbooks WBS = test. workbooks;
Excel. Workbook WB = WBS. Add ("a.xls ");
Excel. Sheets ses = WB. worksheets;
Excel. worksheet Se = (Excel. worksheet) SES. get_item ("sheet3 ");
Excel. Range ra1 = Se. get_range ("B2", "B2 ");
String myvalue = ra1.value2;
The following error occurs during running:
Access denied.
Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.

Exception details: system. unauthorizedaccessexception: Access denied.

The ASP. NET process is not authorized to access the requested resources. For security reasons, the default ASP. NET process is identified as "{machinename} \ ASPnet" and has only limited privileges. Consider granting the ASP. Net Process Identity the permission to access this resource.

To grant ASP. NET write access to a file, right-click the file in resource manager, select "properties", and select the "Security" tab. Click Add to add the {machinename} \ ASPnet user. Highlight this ASP. NET account and select the "write" box in the "allow" column.
1. Find the corresponding folder and add the ASP/net user to it.
2. In resource manager, right-click the file, select "properties", and then select the "Security" tab to give you the asp of the wwwroot directory. . Net users are granted write permissions.
3. Add the read and write permissions for the ASPNET user, or edit the machine. config file under winnt \ Microsoft. NET \ framework \ v1.0.3705 \ config, and set the username value in the processmodel section to System
4. Set the aspnet_wp account to have read and write permissions on Excel. dll.
5. solution:
When using Excel, the Excel process may be locked and cannot be exited. The solution is to stop the Excel process (MyApp) after saving and closing the mybook (workbook. quit ();). The result is that there is always an Excel process on the server. Asp_net users may have insufficient permissions to operate on Excel and configure DCOM. Run dcomcnfg.exe and find the Excel application. Program , Configure its attributes, select "NONE" for the authentication level, select "Interactive User" for the identity, and send the Security Page, start and access to everyone. Note: Check whether any winword process exists in the current process. If any process exists and cannot be terminated, restart the computer. Running your code again is OK. In this way, there will be no insufficient permissions.
6. To grant ASP. NET write access to a file, right-click the file in resource manager, select "properties", and select the "Security" tab. Click Add to add an appropriate user or group. Highlight the ASP. NET account and select the corresponding access permission box. To set permissions, enter dcomcnfg in the Windows runtime box and open com management. In the security of Excel applications, you can add access, run, and configuration permissions for users such as ASPnet, iuser, and IWAM.
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.