【问题标题】:Cannot open Office 2007 files from browser in ASP.NET application无法从 ASP.NET 应用程序中的浏览器打开 Office 2007 文件
【发布时间】:2010-12-06 06:07:30
【问题描述】:

我有一个 ASP.NET 网页,它打开一个请求的文件并将其写入响应,以便该文件应该在浏览器中打开。它工作正常,但 Office 2007 文件类型(.xlsx、.docx、...)无法正常工作。基本上,它什么都不返回,一个空响应,一个空响应。

实际上,它只发生在我的实时服务器(Windows Server 2008)中。在我的测试服务器中,它运行良好(它们也是 Windows Server 2008!)。

代码如下所示:

string filePath = @"C:\mytests\test.docx";
string fileName = @"test";

Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = contentType;
Response.AddHeader(
   "content-disposition",
   "inline; filename=\"" + fileName + "\"");
Response.TransmitFile(filePath);

【问题讨论】:

  • 已发现问题。这是负载平衡器 SSL 过滤问题。谢谢大家的回答和帮助。

标签: c# asp.net office-2007


【解决方案1】:

您的实时服务器是否可能与您的测试服务器位于不同的安全区域?例如Intranet 与 Internet?

【讨论】:

    【解决方案2】:

    在实时服务器上,检查 Internet 信息服务 (IIS) 管理器中的 MIME 类型。

    我认为:

    .docx 应该是 application/vnd.openxmlformats-officedocument.wordprocessingml.document .xlsx 应该是 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

    【讨论】:

    • 尝试将Response.ContentType = contentType; 行替换为Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";(对于.docx 文件)。我想知道这是否是问题所在,因为我猜该页面是一个 .aspx 地址?
    • 实际上,contentType 变量正好包含我用于测试的文件的字符串。页面是一个 .ashx 地址。
    【解决方案3】:

    尝试在末尾添加 Response.End() 以关闭。

    【讨论】:

      【解决方案4】:

      调查受此问题影响的服务器上 Internet Explorer 的 MIME 设置

      【讨论】:

        猜你喜欢
        • 2015-04-22
        • 2021-06-16
        • 2020-12-05
        • 1970-01-01
        • 1970-01-01
        • 2011-03-20
        • 2019-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多