Pep*_*Pep 5 c# asp.net session
我将运行在.NET 1.1服务器上的ASP.NET站点移动到另一台运行.NET 2.0的服务器上.
在其中一个页面中,我有以下代码来检测过期的会话:
protected void Page_Init(object sender, System.EventArgs e) {
if ( Session["XBCPEmail"] == null ) {
Response.Redirect("signin.aspx?expired=yes");
return;
}
}
Run Code Online (Sandbox Code Playgroud)
(会话["XBCPEmail"] == null)在单击其中一个按钮后,在一个意外情况下解析为true(就像会话已过期一样).它只发生在其中一个按钮上.就像同一页面中的其他按钮一样,按钮事件处理程序以此代码重定向到同一页面结束:
Response.Redirect("cpanel.aspx");
Run Code Online (Sandbox Code Playgroud)
我检查并且在Response.Redirect("cpanel.aspx");值的时候(string)Session["XBCPEmail"]是一个有效的字符串,所以我不确定在它之间会发生什么Response.Redirect,Page_Init这可能使得Session["XBCPEmail"]变为null.
哪个可以使.NET 2.0中的Session变量变为null?此代码在1.1中没有该问题,即使在2.0中,它也只影响页面上的一个按钮.
更新:仅当按钮事件处理程序使用下面的代码调用外部.exe程序时才会出现此问题.如果注释掉此代码,则Session变量不为null.如果Session变量为null,创建运行命令行程序的外部进程有什么影响?
private string CallBridge3(string task, string arg1, string arg2, string arg3) {
Process process = new Process();
process.StartInfo.FileName = MapPath("bridgefcp.exe");
process.StartInfo.Arguments = "-" + task + " \"" + arg1 + "\" \"" + arg2 + "\" \"" + arg3 + "\"";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
Run Code Online (Sandbox Code Playgroud)
更新2:在使用IIS 7.5计算机的Windows 2008 R2上安装.NET 4.5后,问题已经消失,而不是使用默认情况下使用的那个,即.NET 2.0.
默认情况下,Response.Redirect终止线程执行,并且在设置会话变量时可能存在竞争条件.文章中描述了在设置Session变量后没有重定向(或者做对了),所以尝试使用另一个不那么暴力的版本:
Response.Redirect("cpanel.aspx", false);
Run Code Online (Sandbox Code Playgroud)
检查你的web.config,也许你有这个标签
<httpCookies requireSSL="true" />
Run Code Online (Sandbox Code Playgroud)
如果是这样,请将其删除.
| 归档时间: |
|
| 查看次数: |
23963 次 |
| 最近记录: |