【问题标题】:MS Ofice Interop error - Retrieving the COM class factory for component with CLSID .... (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))MS Office 互操作错误 - 检索具有 CLSID 的组件的 COM 类工厂 ....(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))
【发布时间】:2020-09-15 16:31:26
【问题描述】:

我知道这可能是一个重复的问题,但我几乎尝试了前面讨论的所有步骤,但没有运气。我也尝试过这个与我的案例类似的链接并完成了所有指令,但再次未能解决错误:Retrieving the COM class factory for component with CLSID failed due to the following error: 80070005 Access is denied

在我的 asp.net Web 应用程序中,我需要打开 Microsoft Word 文件,我可以在本地计算机上使用程序集引用“Microsoft.Office.Interop.Word”来完成此操作。但是当我在服务器(Windows server 2012 r2)上运行它时,我会遇到提到的错误。我还在本地机器上使用的服务器中安装了相同版本的 MS Office。

下面是代码:

 protected void Button1_Click(object sender, EventArgs e)
    {
        fileupload1.SaveAs(Server.MapPath("~/ControlPanel/DocumentCache/" + fileupload1.FileName));
        object filename = Server.MapPath("~/ControlPanel/DocumentCache/" + fileupload1.FileName);
        Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
        Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
        object readOnly = false;
        object isVisible = true;
        object missing = System.Reflection.Missing.Value;
        try
        {
            doc = AC.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref isVisible, ref missing, ref missing, ref missing);
            txt_DContent.Text = doc.Content.Text;
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.ToString();
        }
        
        INSERTDATAT(); // Method to insert the record
        // AC.Quit(); This is to quit MS word that was opened to read the ms word file in textbox txt_DContent
        ((_Application)AC.Application).Quit(false);
        Session["MyFile"] = fileupload1.FileName;
    }

【问题讨论】:

标签: c# ms-word office-interop


【解决方案1】:

我已通过以下 2 个步骤修复了该错误:

  1. 在 web.config 文件的 中添加<identity impersonate="true" />

  2. 我在我的数据库中为 NT AUTHORITY\IUSR 创建了一个安全登录,并提供了所有必需的权限,如下所示:

【讨论】:

    猜你喜欢
    • 2017-12-18
    • 2017-08-22
    • 1970-01-01
    • 2012-04-25
    • 2011-05-14
    • 1970-01-01
    • 2012-02-17
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多