无法在ASP.NET应用程序中从浏览器打开Office 2007文件

时间:2009-10-13 09:10:06

标签: c# asp.net office-2007

我有一个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);

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

尝试在结束时添加Response.End()以关闭。

答案 2 :(得分:0)

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

我想:

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

答案 3 :(得分:0)

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

相关问题