ASP.Net Com-InterOp Excel Generation issue when hosting

你说的曾经没有我的故事 提交于 2020-01-13 08:08:15

问题


In my ASP.Net application I'm generating a Excel file using MsExcel Object Libby (Com-InterOp) . The application worked fine in the VS dev. environment.

But when I host it in the server I'm getting following error, if I'm no user is logged in to the server through Remote desktop Connection.

"Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from HRESULT: 0x8000401A)."

I've set DCOM configurations as well. The strange thing is that at least one user should be connected to the server through RDC. If so everyone can generate excels. If not above error throws. Rest of the functionality of the application works fine.

The server is Windows Server 2008, IIS7. And the users connecting the application through a VPN.

Has any one experienced a issue like this?

Thanks in advance.


回答1:


In the end I created user who is admin on the computer with the web service, and then I set this user like shown on the screen below:

That worked. And we didn't have to let the computer be locked.




回答2:


The problem is that the 'Identity' set up for the application lacks sufficient privileges. This could be for several reasons, but before we get into those, let's check out where this identity is configured. Open Control Panel, Administrative Tools, and double-click Component Services. Expand COM+ Applications, right-click the application in question, hit Properties, and switch to the Identity tab.

One possible reason is that, when setting the identity for your application, you simply chose a user that doesn't have access to the DLL, or to a file or system call the DLL touches.

If this identity is set to the 'Interactive User', then the above error might occur when the user currently logged in to the machine is a peon, or when nobody is logged in at all. This is the primary reason why this error is never detected in development... the user developing the COM+ application, and in complete control of the machine, is also the user logged in and running as the interactive user.

You should make sure to use a local user account with sufficient privileges, if that's what your DLL requires. User whom uses VPN may find difficulty due to this.




回答3:


Microsoft does not recommend or support server-side Automation of the Excel application in a server environment like ASP.NET, see here . Better use Excel package plus (xslx) or Excel library (xls)




回答4:


Using Office Interop on the server is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Since Windows Vista MS introduced several security-related measures which prevent a Windows Service (IIS is just a special case of that) from doing "desktop-like" things... which means you would have to circumvent several security measures (impersonation alone won't cut it!) to get it to work (NOT recommended!).

NOTE that the Integrated VS web server does NOT simulate the behaviour of IIS regarding permissions etc.

To deal with Excel in a server-scenario there are several options (free and commercial) out there:

I can recommend Aspose.Cells and Flexcel... didn't try SpreadsheetGear but hear+read lots of good things about it.

Free options (though for xlsx format only!) are for example OpenXML 2 from MS and EPPlus.




回答5:


Just set the Identity to this User and enter the username and password of a user who has sufficient rights. In my case I entered a user of power user group.




回答6:


I made research on this problem, which I also had. I did that: http://forums.asp.net/t/1093228.aspx

I don't know how good solution it is but it works. :)

Type dcomcnfg in cmd

go to Component Services ->My Computer ->Com Security ->Lauch and Activate Permissions ->Edit Default ->Add...

Now add Network Service and allow all permisions to it.




回答7:


I have the same situation when try to read an uploaded Excel file. Let try these steps. It works for me.

  1. Create a local account (set password and tick never expired)
  2. Add created account in step 1 to group IIS_IUSRS
  3. Modify your web config ...
  4. Logoff your server and try.

Hope it is helpful for you.




回答8:


Thanks for @Rofans.Net, based on the points provided by him we identified that the server, which the app was hosted was in a 3rd party data center and there is no user logged on to the server all the time. Only logged on users are the RDC users.

So we managed to have a user all ways logged in and and put the computer in the locked stated so that all ways it has a logged in user.

This is the only way we found and if anyone found a better way please add.

Thanks.



来源:https://stackoverflow.com/questions/9095688/asp-net-com-interop-excel-generation-issue-when-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!