C# 托管时 ASP.Net Com-InterOp Excel 生成问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9095688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.Net Com-InterOp Excel Generation issue when hosting
提问by Thanushka
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.
在我的 ASP.Net 应用程序中,我使用 MsExcel Object Libby (Com-InterOp) 生成一个 Excel 文件。该应用程序在 VS dev 中运行良好。环境。
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)."
“由于以下错误,检索具有 CLSID {00024500-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:8000401a 服务器进程无法启动,因为配置的身份不正确。请检查用户名和密码。(来自 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.
我也设置了 DCOM 配置。奇怪的是,至少有一个用户应该通过 RDC 连接到服务器。如果是这样,每个人都可以产生卓越。如果不是上面的错误抛出。应用程序的其余功能运行良好。
The server is Windows Server 2008, IIS7. And the users connecting the application through a VPN.
服务器是Windows Server 2008,IIS7。以及通过 VPN 连接应用程序的用户。
Has any one experienced a issue like this?
有没有人遇到过这样的问题?
Thanks in advance.
提前致谢。
采纳答案by Thanushka
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.
感谢@Rofans.Net,根据他提供的要点,我们确定托管该应用程序的服务器位于第 3 方数据中心,并且一直没有用户登录该服务器。只有登录用户才是 RDC 用户。
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.
谢谢。
回答by Antonio Bakula
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)
Microsoft 不建议或支持在 ASP.NET 等服务器环境中对 Excel 应用程序进行服务器端自动化,请参见此处。更好地使用Excel 包 plus(xslx) 或Excel 库(xls)
回答by rofans91
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.
问题是为应用程序设置的“身份”缺乏足够的权限。这可能有多种原因,但在我们进入这些之前,让我们检查一下此身份的配置位置。打开控制面板、管理工具,然后双击组件服务。展开 COM+ 应用程序,右键单击有问题的应用程序,点击属性,然后切换到身份选项卡。
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.
一个可能的原因是,在为您的应用程序设置标识时,您只是选择了一个无权访问 DLL 或 DLL 接触的文件或系统调用的用户。
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.
如果将此身份设置为“交互式用户”,则当当前登录机器的用户是peon,或者根本没有人登录时,可能会出现上述错误。这就是为什么在开发中从未检测到此错误的主要原因……开发 COM+ 应用程序并完全控制机器的用户也是以交互用户身份登录和运行的用户。
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.
如果您的 DLL 需要,您应该确保使用具有足够权限的本地用户帐户。使用 VPN 的用户可能会因此而感到困难。
回答by Yahia
Using Office Interop on the server is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
MS 不支持在服务器上使用 Office Interop - 请参阅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!).
由于 Windows Vista MS 引入了几种与安全相关的措施,这些措施可以防止 Windows 服务(IIS 只是其中的一个特例)做“类似桌面”的事情...... 't cut it!) 让它工作(不推荐!)。
NOTE that the Integrated VS web server does NOT simulate the behaviour of IIS regarding permissions etc.
请注意,集成 VS Web 服务器不会模拟 IIS 有关权限等的行为。
To deal with Excel in a server-scenario there are several options (free and commercial) out there:
要在服务器方案中处理 Excel,有几种选择(免费和商业):
I can recommend Aspose.Cellsand Flexcel... didn't try SpreadsheetGearbut hear+read lots of good things about it.
我可以推荐Aspose.Cells和Flexcel... 没有尝试过SpreadsheetGear,但听到+阅读了很多关于它的好东西。
Free options (though for xlsx format only!) are for example OpenXML 2 from MSand EPPlus.
回答by ritu
Just set the Identityto 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.
只需将 设置Identity为此用户并输入具有足够权限的用户的用户名和密码即可。在我的情况下,我输入了一个超级用户组的用户。
回答by ritu
I made research on this problem, which I also had. I did that: http://forums.asp.net/t/1093228.aspx
我对这个问题进行了研究,我也有。我这样做了: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.
在cmd中输入dcomcnfg
转到组件服务 -> 我的电脑 -> 通信安全 -> 启动并激活权限 -> 编辑默认值 -> 添加...
现在添加网络服务并允许所有权限。
回答by ritu
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:
最后,我在具有 Web 服务的计算机上创建了管理员用户,然后我设置了这个用户,如下面的屏幕所示:


That worked. And we didn't have to let the computer be locked.
那奏效了。而且我们不必让计算机被锁定。
回答by culithay
I have the same situation when try to read an uploaded Excel file. Let try these steps. It works for me.
尝试读取上传的 Excel 文件时,我遇到了同样的情况。让我们试试这些步骤。这个对我有用。
- Create a local account (set password and tick never expired)
- Add created account in step 1 to group IIS_IUSRS
- Modify your web config ...
- Logoff your server and try.
- 创建本地帐户(设置密码并勾选永不过期)
- 将步骤 1 中创建的帐户添加到组 IIS_IUSRS
- 修改您的网络配置...
- 注销您的服务器并尝试。
Hope it is helpful for you.
希望对你有帮助。

