问题描述:

Windows Server® 2008 R2 x64

 Office2010

 IIS7.5

 Browser发送请求给Server,Server查询数据库并把数据写入到.doc的模板中,然后把文件返回给Browser。直接运行VS程序运行正常。但是一旦通过IIS来访问请求的话,就报错。

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


解决思路:

 因为IIS用户没有操作Word组件的权限。


解决办法:

 1. 在IIS中修改应用程序的Identity为LocalSystem

 2.在DCOM Config中,把Microsoft Word的操作权限给IIS用户

   首先,解决在DCOM Config中找不到Microsoft Word组件的问题:

       On 64 bit system with 32 bit Office try this:

  1. Start

  2. Run

  3. mmc -32

  4. File

  5. Add Remove Snap-in

  6. Component Services

  7. Add

  8. OK

  9. Console Root

  10. Component Services

  11. Computers

  12. My Computer

  13. DCOM Config

  14. Microsoft Excel Application

  15. ...

  其次,解决一个系统bug:

   Windows 2008 Server x64

 Please make this folder.

 C:\Windows\SysWOW64\config\systemprofile\Desktop

Windows 2008 Server x86

 Please make this folder.

 C:\Windows\System32\config\systemprofile\Desktop


 3.把文件夹的操作权限给IIS用户

用了2天的时间,搞定!


参考文件:

http://www.computerperformance.co.uk/Logon/code/code_80070005.htm#Local_Security_and_Policies_and_DCOM

http://forums.asp.net/t/931005.aspx/2/10

http://social.technet.microsoft.com/Forums/en-US/w7itproappcompat/thread/dde69147-a01a-4eb1-8ea9-31adbf874bed

http://social.technet.microsoft.com/forums/en-US/officesetupdeploylegacy/thread/334c9f30-4e27-4904-9e71-abfc65975e23?prof=required)and

http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91