简体   繁体   中英

Exporting Gridview to CSV now including the parent page html content after moving site to a new server

I have a simple export gridview to csv function in a c#.aspx page hosted in IIS 7.5 on a Windows 2008 server which has worked fine for a long time. I have recently migrated this site to a new windows 2016 server application server, hosted on IIS 10.0 and the code base is identical. On the new server however, the exported data now includes all of the html from the parent page too. I have checked that the mimetype for *.csv is present in the IIS config and it is.

Code snippet for reference:

var stream = new MemoryStream();
_report.ToFile(stream);
byte[] bytes = stream.ToArray();
stream.Flush();
stream.Close();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + Guid.NewGuid().ToString() + ".csv");
HttpContext.Current.Response.AddHeader("Content-Length", bytes.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.BinaryWrite(bytes);

Just to confirm, the only change is the location of where the site is running, the code base is unchanged.

Ending the response worked: HttpContext.Current.Response.End(); Thank you all. Interesting that when running the same code on IIS 7,5? the response didn't need to be ended for the page markup not to be included in the csv export??!!

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