[英]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.