ユーザーがASP.NETアプリケーションからファイルをダウンロードすると、ファイルをダウンロードしてから数秒後にセッションが期限切れになります。任意のタスクを実行できるセッションが期限切れになる前ですが、約5〜10秒後にセッションが再開され、ログアウトされます。
これを示すための簡単なページを作成しました。この単純なページを実行するには、新しいasp.net c#プロジェクトを作成してから、コードを新しいページに挿入します。
編集:これはIE7の問題のようです。FirefoxとChromeは影響を受けません。
セッションの再開を担当するコードは次のとおりです。
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();
この問題を再現するには:
- 以下のコードをasp.netページにコピーします。
- IEを使用します(私はIE7を使用しましたが、FirefoxとChromeにはこの問題はないようです)
- セッションが新しいことに注意してください。
- ページを更新; セッションは新しいものではないことに注意してください。
- ファイルをダウンロードして保存します。
- 「Sessionisnew」のテキストが再表示されるまで(約10秒)、「RefreshPage」ボタンを数回押します。
以下は、簡単なレクリエーションのコードです。
<%@ 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>