代码在开发服务器上运行,但不在 IIS 上运行

Code runs on development server but not on IIS

我有一个 Web 应用程序,用户 运行 查询(通过 Web 界面)并获得 excel 格式的输出。有时此输出包含超过 300k 条记录。用户需要此数据进行进一步研究。

现在为了加快动态 excel 创建如此大量的数据,我们正在使用 "Microsoft.Office.Interop.Excel" COM 对象。

我们的代码在内置 asp.net 开发服务器上完全可以正常工作。然而,当托管在 IIS 上时,它给我们 "Access is Denied" 错误(具体错误如下所示)。

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

我已将所有权限授予 IIS 用户,但仍然无法正常工作。 我已经尝试了 Windows Server 2012 R2 以及 Windows 7 OS 但它们都不起作用。

我已经对 "DCOMCNFG" 进行了更改,并在 "COM Security" 选项卡下授予网络用户访问权限。

我可以采取哪些额外步骤来完成这项工作?

查看以下链接 -

"Retrieving the COM class factory for component.... error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

http://forums.iis.net/t/1205506.aspx?Retrieving+the+COM+class+factory+for+component+with+CLSID+failed+due+to+the+following+error+80070005+access+is+denied

https://waheedrous.wordpress.com/2014/01/26/error-office-interop-assemblies/

这是 COM 权限问题。

Start > Run > dcomcnfg

导航至 Component Services > Computers > My Computer > DCOM Config

找到 Microsoft Excel Application

Right click > Properties

在安全选项卡上:Select Security 下启动和 Activation Permissions 并单击 Edit…

添加站点所在的帐户运行(例如:网络服务)并分配本地启动和本地激活权限

Source

还应启用 ASP.NET 身份验证。

我认为要使其工作,必须在服务器上安装 office。 因此,如果不是这种情况,请在服务器上安装 Office。 (替代方法是使用 OpenXml http://www.microsoft.com/en-us/download/details.aspx?id=30425

我决定放弃在服务器上使用 COM 对象进行 Excel 操作。相反,我决定使用 EPPlus open office XML SDK 来生成 Excel 文件。这对服务器没有任何额外的安全许可要求。