使用ASP.NET字自动化 [英] Word Automation with ASP.NET

查看:1041
本文介绍了使用ASP.NET字自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用的Microsoft Word自动化asp.net一个旧的应用程序,我需要在Windows Server 2012中R2 64位的Office 2013标准x86安装。我知道,在服务器技术,如IIS办公自动化应该避免,但我没有绿灯改写此刻的应用程序,所以我必须把它原样。

I have an old application that uses Microsoft Word automation in asp.net and I need to install it on a Windows Server 2012 R2 x64 with Office 2013 Standard x86. I know that Office automation in server technologies like IIS should be avoided but I don't have the green light to rewrite the application at the moment, so I have to take it as-is.

起初,我启动了应用程序,它给了这个错误:

Initially I started the application and it gave this error:

检索COM类工厂具有CLSID组件{000209FF-0000-0000-C000-000000000046}失败,原因是出现以下错误:80070005访问被拒绝。 (异常来自HRESULT:0X80070005(E_ACCESSDENIED))。

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

我发现了一些信息网上的{000209FF-0000-0000-C000-000000000046}是通用字的标识,没有具体的版本。

I found some information online that {000209FF-0000-0000-C000-000000000046} is the identifier of generic Word, no specific version.

我到组件服务 - >我的电脑 - > DCOM配置 - > Microsoft Word 97中 - 2003文档(注意,是微软Word或MS Word或Word中没有节点,而有一个用于Microsoft Excel),并改变了安全允许IIS程序池的用户本地启动,本地激活和本地访问。这使得应用需要一些时间来作出回应(超过一分钟),并失败,出现以下错误:

I went to Component Services -> My Computer -> DCOM Config -> Microsoft Word 97 - 2003 Document (note that there is no node for Microsoft Word or MS Word or Word while there is one for Microsoft Excel) and changed the security to allow the IIS AppPool user "Local Launch", "Local Activation" and "Local Access". This makes the application take some time to respond (more than a minute) and fail with the following error:

检索COM类工厂具有CLSID组件{000209FF-0000-0000-C000-000000000046}失败,原因是出现以下错误:80080005服务器执行失败(异常来自HRESULT:0x80080005(CO_E_SERVER_EXEC_FAILURE))。

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

与此同时事件查看器系统日志显示:

At the same time the event viewer System log shows:

服务器{000209FF-0000-0000-C000-000000000046}没有用DCOM限定的时间内注册。

The server {000209FF-0000-0000-C000-000000000046} did not register with DCOM within the required timeout.

我在网上搜索,发现了一些信息的访问权限可能并不确定,包括系统驱动器路径和注册表。我跑进程监视器,并检查该进程在试图打开。我给IIS程序池用户完全访问以下内容:

I searched online and found some information that access rights might not be OK, including system drive paths and registry. I ran Process Monitor and checked what the process is trying to open. I gave the IIS AppPool user full access to the following:


  • C:\\ WINDOWS \\ Syswow64资料\\ CONFIG \\ systemprofile

  • C:\\ WINDOWS \\ TEMP

  • HKU.DEFAULT \\软件\\微软\\办公室

  • HKLM \\ SOFTWARE \\ Wow6432Node \\微软\\办公室

  • HKLM \\ SOFTWARE \\ Wow6432Node \\微软\\ Shared工具

当我再次运行应用程序只显示,进程监视器这似乎只是试图读取不同的配置一些访问问​​题。本身并没有表现出任何类型的错误更多的应用程序,它只是冻结。我没有安装Visual Studio在该机器上,但我没有看到在应用程序日志的任何错误,所以没有异常被抛出。

When I ran the application again it only showed a few access problems in Process Monitor which seem to be just attempts to read different configurations. The application itself did not show any kind of error any more, it just freezed. I don't have Visual Studio installed on that machine, but I don't see any errors in the application logs, so no exceptions were thrown.

我想也设置在DCOM标识特定的用户(本地管理员),但并没有改变。

I tried also setting a specific user (local administrator) in the DCOM Identity but there was no change.

现在我恢复了所有权限,我回到了0x80080005错误,因为它至少给我一些资料,试图去。

Now I restored all permissions and I am back to the 0x80080005 error because it at least gives me some information to try to go with.

我成功重现错误与本code一个简单的应用:

I succeeded to reproduce the error in a simple application with this code:

try
{
    l1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    var application = new Microsoft.Office.Interop.Word.Application();
    l2.Text = "OK";
}
catch (Exception ex)
{
    this.Label2.Text = ex.ToString().Replace("\r\n", "<br/>");
}

它也不能在Windows 8 64位的Office 2013专业版x64,一模一样的错误。

It fails also on Windows 8 x64 with Office 2013 Pro x64, with exactly the same error.

如果我冒充当前用户是管理员,那么它的工作原理。然而,即使添加IIS APPPOOL \\默认应用到管理员组,但它仍然会失败。

If I impersonate the current user to be an administrator, then it works. However even adding IIS APPPOOL\DefaultAppPool to the administrators group, it still fails.

在接下来的步骤中任何想法?

Any ideas on the next steps?

推荐答案

所以这是到底是什么工作:

So this is what worked at the end:


  • 创建一个管理员用户,并设置在Word中DCOM设置与它运行

  • 在设置给激活,启动和访问权限的应用程序池的用户以及IIS_IURS和IUSR。请注意,如果你不给的权利为别人,只对程序池的用户中,Windows仍然会报告该程序池用户没有足够的权限,这完全是误导

我也想通了什么与冷冻Word中的问题是:创建新的文件导致Word将在它告诉你该文件可能是危险的特殊模式打开。当然,使用COM,你看不出问题,但那就不是能够继续下去,直到你允许它。这是在Word 2013年新的行为,这就是为什么我以前是没有的。

I also figured out what the problem with the freezing Word was: creating the new file was causing Word to open in the special mode where it tells you that the file might be dangerous. Of course using COM you don't see the problem but it would then not be able to continue until you allow it. This is a new behavior in Word 2013 and that's why I didn't have it before.

这篇关于使用ASP.NET字自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆