Excel: Access is denied

调用Excel组件的时候,有时候总会忘记一些东西,这次又是,忘记配置的DCOM中Excel的权限,结果程序总是报错:Access is denied.
后来才想起来,原来DCOM又忘记配置了~

然后在网上查,又找到了另一种方法,就是在web.config中设置一个节点,也可以同样达到这个效果,不需要设置DCOM权限,两种方法各有利弊吧

U need to impersonate the aspnet account when trying to access office applications which requires administrator privileges. By default the asp.net application runs with the privileges of the account : machinename\aspnet

and, this account does not have administrator privileges by default.

u can do 3 things to use an administrator account for your asp.net applications:

1. Add the machinename\aspnet account to the Administrators group by using the computer management console.

2. Use an account which has administrator privileges on the web server machine: to do this, open ur web.config file, just below the authentication tag write this line:
< identity  impersonate ="true"  userName ="machinename\administrator"  password ="admin password"   />


this is called impesonating asp.net to use a fixed account.

3. Open ur web.config file, just below the authentication tag write this line:
< identity  impersonate ="true"   />

and, logon with an administrator account on this machine before running the asp.net application. This method is called impersonating asp.net to use the logged on account.

FYI: http://support.microsoft.com/default.aspx?scid=kb;en-us;257757

你可能感兴趣的:(Access)