但它的工作正常 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)