简体   繁体   English

Chome下载aspx页面,而不是像IE和firefox一样下载Excel

[英]Chome downloads aspx page instead of an excel like it does in IE and firefox

I have a webpage that allows users to download excel reports, in Chrome, it just tries to download an aspx page instead of the excel like it successfully does in IE and Firefox. 我有一个网页,允许用户下载Excel报表,在Chrome中,它只是尝试下载一个aspx页面,而不是像在IE和Firefox中一样成功下载excel。

Is this a known issue and is there a workaround? 这是一个已知问题,是否有解决方法?

I am using this in VB: 我在VB中使用它:

db.subRunReader(resultSQL)
dgProperties.DataSource = db.sqlReader
dgProperties.DataBind()
db.subCloseReader()
db.subCloseConnection()

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False

Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dgProperties.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
Response.Redirect(Request.Url.ToString())

Thanks. 谢谢。

Not sure about your specific situation, but in general whenever you want a file downloaded, it is a good idea to add a Content-Disposition header. 不确定您的具体情况,但是通常在您希望下载文件时,最好添加Content-Disposition标头。 In ASP.NET MVC it would be done like this: 在ASP.NET MVC中,将这样完成:

Response.Headers["Content-Disposition"] = 
    "attachment;filename=yourfile.xls";

I expect in ASP.NET 2.0 it would be something similar. 我期望在ASP.NET 2.0中会类似。 This tells the browser that it needs to download the file. 这告诉浏览器它需要下载文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IE 11下载页面而不是打开页面,可在Chrome和Firefox中使用 - IE 11 Downloads Page instead of opening it, works in Chrome and Firefox 为什么我的Aspx页面在FireFox和IE中呈现不同的HTML - Why is my Aspx page rendering different HTML in FireFox and IE CSS HTML:Chome中的文本换行:在Firefox和IE中可以正常工作 - CSS HTML: Text Wraps in Chome: Works fine in Firefox and IE IE8的奇怪问题(但不是IE7 / Firefox / Chome) - 使用Javascript后内容溢出 - Weird problem with IE8 (but not IE7/Firefox/Chome) - content overflowing after Javascript used 为什么这个字体系列在Chome,Safari,Opera和IE &lt;9中不起作用,但在Firefox和IE9中有效? - Why doesn't this font family work in Chome, Safari, Opera and IE < 9 but works in Firefox and IE9? 用于渲染图像的ASPX页面突然无法在Firefox中运行。 适用于Chrome / IE - ASPX page to render image suddenly not working in Firefox. Works in Chrome/IE aspx页面中的锚标记onclick事件在IE(11)中有效,但在Chrome和Firefox中无法响应 - Anchor tag onclick event in aspx page works in IE (11) but fails to respond in Chrome and Firefox 图标位于Chome和Firefox而非Safari中 - Icons Centered in Chome and Firefox but not Safari 为什么该页面在IE,Firefox和Chrome之间不一样 - Why does this page look different between IE, Firefox & Chrome 页面不会在FIREFOX上显示内容,但会在Chrome甚至IE中显示 - Page Doesn't show content on FIREFOX, but does in Chrome, and even IE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM