在 IE 中无法将渲染的 HTML 页面导出到 Word

发布于 2024-10-22 21:44:32 字数 1014 浏览 1 评论 0原文

我有一个渲染的 HTML 页面,我将其导出到 MS Word 并单击按钮即可下载。

这是按钮单击中的代码片段。

` Me.EnableViewState = False
    Response.ContentType = "application/vnd.ms-word"
    Response.AddHeader("Content-Disposition", "attachments;filename=XXXXXXX.doc")
    Response.Buffer = True
    Response.BufferOutput = True`

该功能在 Firefox 和 Firefox 中运行良好。当我检查系统测试环境(本地)时的IE。然而,当它转移到托管服务器(生产环境)时,该功能在 IE 中无法工作,但在 Firefox 中仍然可以完美工作。

我不确定在哪里检查确切的问题。这可能是与缓存相关的问题吗?

在 IE 中,它只是不打开下载窗口,当渲染的 HTML 内容类型发生更改并且响应流被刷新时,我们将获得该下载窗口。没有抛出异常。

我收到以下响应标头:

HTTP/1.0 200 OK
Cache-Control: private 
Content-Length: 15189 
Content-Type: application/vnd.ms-word; 
charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 
Content-Disposition: attachments;filename=NewAccountForm.doc X-Powered-By: ASP.NET 
Date: Fri, 18 Mar 2011 10:18:07 GMT X-Cache: MISS from Gateway X-Cache-Lookup: MISS from Gateway:808 Via: 1.0 Gateway (squid/3.0.STABLE10) Proxy-Connection: keep-alive

I have a rendered HTML page that I am exporting to MS Word and downloading on a button click.

Here is the code snippet in the button click.

` Me.EnableViewState = False
    Response.ContentType = "application/vnd.ms-word"
    Response.AddHeader("Content-Disposition", "attachments;filename=XXXXXXX.doc")
    Response.Buffer = True
    Response.BufferOutput = True`

The functionality works perfectly well in Firefox & IE when I checked in system testing environment (locally). However when it was moved on to the hosting server (production environment) the functionality is not working in IE but is still working perfectly in Firefox.

I am not sure on where to check for the exact issue. Could it be a caching related problem?

In IE it is just not opening the download window which we will obtain when the rendered HTML content type is changed and the response stream is flushed. No exception is thrown.

I received the following response header:

HTTP/1.0 200 OK
Cache-Control: private 
Content-Length: 15189 
Content-Type: application/vnd.ms-word; 
charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 
Content-Disposition: attachments;filename=NewAccountForm.doc X-Powered-By: ASP.NET 
Date: Fri, 18 Mar 2011 10:18:07 GMT X-Cache: MISS from Gateway X-Cache-Lookup: MISS from Gateway:808 Via: 1.0 Gateway (squid/3.0.STABLE10) Proxy-Connection: keep-alive

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黯然 2024-10-29 21:44:32

您的托管环境是否添加了 http 标头? IIS 可以轻松配置为添加标头搞乱了你想要发送的内容。这实际上很常见,并且可能是问题所在。您需要确定这一点,因此这里有一个调查建议:

尝试使用 WebClient 类并查看响应 标题

编辑 - 更新

放置

Response.Clear();

我刚刚注意到 - 您是否记得在添加标题之前 ?它可能根本不是托管环境。然而,考虑到它在本地工作,而不是在您的托管环境中工作,并且假设它是相同的代码,在我看来,托管环境仍然有些不同,最合乎逻辑的选择是标头。

Is your hosted environment adding http headers? IIS could easily be configured to add headers that are messing up what you want to send out. It's actually quite common, and could be the issue. You'll need to determine this for sure, so here's a suggestion for investigating:

Try using a WebClient class and look at the Response headers.

Edit - updated

I just noticed - did you remember to put

Response.Clear();

before adding headers? It may not be the hosting environment at all. However, given that it works locally and not at your hosting environment, and assming that it is the same code, it still looks to me like something is different about the hosted environment, and the most logical option would be the headers.

风透绣罗衣 2024-10-29 21:44:32

我设置 Response.Charset = "" 并在导出 HTML 后始终执行 Response.Flush()、Response.End() 和 Response.Close()。

I set Response.Charset = "" and always do Response.Flush(), Response.End(), and Response.Close() after I export the HTML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文