简体   繁体   中英

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.

Is this a known issue and is there a workaround?

I am using this in 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. In ASP.NET MVC it would be done like this:

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

I expect in ASP.NET 2.0 it would be something similar. This tells the browser that it needs to download the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM