会议文件下载后过期 [英] Session expires after file download
问题描述
当用户从我的ASP.NET应用程序下载文件,会话过期几秒钟后,他们下载的文件。会话过期之前可以执行任何任务,但约5-10秒钟后,会重新启动,他们得到注销。
我创建了一个简单的页面来证明这一点。要运行这个简单的页面,创建一个新的asp.net C#项目,然后将code到一个新的一页。
编辑:这似乎是IE7的问题。火狐和Chrome不会受到影响。
我相信,code负责会话重新启动是:
HttpContext.Current.Response.ContentType =文/ XML;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(内容处置,附件;文件名=的test.xml);
HttpContext.Current.Response.Write(<试验>这是一个试验&下; /试验>);
HttpContext.Current.Response.End();
要重现此问题:
- 低于code复制到一个asp.net页面。
- 使用IE浏览器(我使用IE7,Firefox和Chrome似乎不存在此问题)
- 请注意,本次会议是新的。
- 刷新页面;注意到,本次会议是不是新的。
- 下载文件并保存它。
- 点击刷新页面按钮几次,直到会议是新的文本重新显示(约10秒)。
下面是code的简单娱乐:
<%@页面语言=C#AutoEventWireup =真正的%GT;
!< DOCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< HTML的xmlns =http://www.w3.org/1999/xhtml>
<头=服务器>
<标题>无标题页< /标题>
< /头>
<身体GT;
<脚本=服务器>
私人字符串sessionString {
获得{
返回HttpContext.Current.Session [sessionString] == NULL?空:HttpContext.Current.Session [sessionString]的ToString();
}
集合{
HttpContext.Current.Session [sessionString] =值;
}
}
保护无效的Page_Load(对象发件人,EventArgs的发送){
Label1.Text = sessionString? 会话为空;
如果(sessionString == NULL){
Label1.Text =会议是新的;
Label1.BackColor = System.Drawing.Color.Red;
sessionString =会话目前不是空;
}
其他{
Label1.Text = sessionString;
Label1.BackColor = System.Drawing.Color.White;
}
}
保护无效LinkButton1_Click(对象发件人,EventArgs五){}
保护无效LinkButton2_Click(对象发件人,EventArgs的发送){
HttpContext.Current.Response.ContentType =文/ XML;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(内容处置,附件;文件名=的test.xml);
HttpContext.Current.Response.Write(<试验>这是一个试验&下; /试验>);
HttpContext.Current.Response.End();
}
< / SCRIPT>
<表ID =form1的=服务器>
< DIV>
< ASP:标签ID =Label1的=服务器文本=标签>< / ASP:标签> < BR />
< ASP:LinkButton的ID =LinkButton1=服务器的onclick =LinkButton1_Click>刷新页面< / ASP:LinkButton的> < BR />
< ASP:LinkButton的ID =LinkButton2=服务器的onclick =LinkButton2_Click>下载文件< / ASP:LinkButton的> < BR />< BR />
< B个步骤来重新创建:LT; / B>
<&OL GT;
<立GT;下载文件并保存< /李>
<立GT;点击刷新页面按钮几次,直到会议是新的文本重新显示< /李>
<立GT;回答我的问题解释究竟发生了什么事<!/李>
< / OL>
< / DIV>
< /表及GT;
< /身体GT;
< / HTML>
事做这个(可能是一个类似的问题)?也许使用Fiddler查看更详细发生到cookie。
When a user downloads a file from my ASP.NET application, the session expires a few seconds after they download the file. Before the session expires that can perform any task, but after about 5-10 seconds, the session is restarted and they get logged out.
I've created a simple page to demonstrate this. To run this simple page, create a new asp.net c# project, then insert the code into a new page.
EDIT: This appears to be a IE7 problem. Firefox and Chrome are unaffected.
I believe the code responsible for the session restart is:
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=test.xml");
HttpContext.Current.Response.Write("<test>this is a test.</test>");
HttpContext.Current.Response.End();
To recreate this problem:
- Copy the code below into an asp.net page.
- Use IE (I used IE7, firefox and chrome don't appear to have this issue)
- Notice that the session is new.
- Refresh the page; notice that the session is not new.
- Download the file and save it.
- Hit the "Refresh Page" button a couple of times until the "Session is new" text is redisplayed (about 10 seconds).
Below is the code for the simple recreation:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<script runat="server">
private string sessionString {
get {
return HttpContext.Current.Session["sessionString"] == null ? null : HttpContext.Current.Session["sessionString"].ToString();
}
set {
HttpContext.Current.Session["sessionString"] = value;
}
}
protected void Page_Load(object sender, EventArgs e) {
Label1.Text = sessionString ?? "Session is null";
if(sessionString == null) {
Label1.Text = "Session is new";
Label1.BackColor = System.Drawing.Color.Red;
sessionString = "Session is now not null";
}
else {
Label1.Text = sessionString;
Label1.BackColor = System.Drawing.Color.White;
}
}
protected void LinkButton1_Click(object sender, EventArgs e) { }
protected void LinkButton2_Click(object sender, EventArgs e) {
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=test.xml");
HttpContext.Current.Response.Write("<test>this is a test.</test>");
HttpContext.Current.Response.End();
}
</script>
<form id="form1" runat="server">
<div>
<asp:Label id="Label1" runat="server" text="Label"></asp:Label> <br />
<asp:LinkButton id="LinkButton1" runat="server" onclick="LinkButton1_Click">Refresh Page</asp:LinkButton> <br />
<asp:LinkButton id="LinkButton2" runat="server" onclick="LinkButton2_Click">Download File</asp:LinkButton> <br /><br />
<b>Steps to recreate:</b>
<ol>
<li>Download the file and save it.</li>
<li>Hit the "Refresh Page" button a couple of times until the "Session is new" text is redisplayed.</li>
<li>Answer my question explaining what the heck is going on!</li>
</ol>
</div>
</form>
</body>
</html>
Something to do with this (could be a similar issue)? Maybe use Fiddler to see what is happening in more detail to the cookie.
这篇关于会议文件下载后过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!