- IIS7.5
- 视窗服务器 2008
- ASP.NET4.0
但它在 IIS5.1 中运行良好
fileContent = @"<table><tr><td>Name</td><td>Age</td><td></td></tr></table>";
// byte[] content = fileContent.ToByteArray();
HttpContext currentRequest = System.Web.HttpContext.Current;
//fileContent = currentRequest.Server.HtmlEncode(fileContent);
currentRequest.Response.Clear();
currentRequest.Response.ClearContent();
currentRequest.Response.ClearHeaders();
//currentRequest.Response.AddHeader("Accept-Ranges", "bytes");
currentRequest.Response.Buffer = true;
//fileName = currentRequest.Server.UrlEncode( fileName);
if (toDownload)
{
currentRequest.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", fileName));
}
else
{
currentRequest.Response.AddHeader("Content-Disposition", string.Format("filename=\"{0}\"", fileName));
}
currentRequest.Response.AddHeader("Content-Length", fileContent.Length.ToString());
//currentRequest.Response.ContentType = GetContentType(StreamFileType.MSOffice2003ExcelDocument);
currentRequest.Response.ContentType = "application/vnd.xls";
currentRequest.Response.Write(fileContent);
currentRequest.Response.Flush();
currentRequest.Response.Close();
HttpContext.Current.ApplicationInstance.CompleteRequest();
只要文件在新页面中打开,就会创建新的 SessioniD。
如果我检查它会重置的会话
if (this.Session.IsNewSession)