会话变量未在Response.Redirect上维护

时间:2013-06-27 04:40:19

标签: asp.net session web-config session-variables response.redirect

我有一个登录页面,我在登录时重定向到另一个页面。 我在Session中保存了一些数据,但无法在Page2.aspx中恢复相同的数据。

我发现一些博客和网站说明了同样的问题,但他们的解决方案无效。

以下是我来自Page1.aspx的代码

  

会话[“用户名”] =姓名;的Response.Redirect( “〜/ Page2.aspx”,假);

在Page2.aspx

 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["Username"] != null)
         ClientScript.RegisterStartupScript(GetType(), "", "sendtoken();", true);
     else
         Response.Redirect("Page1.aspx");                 
}

此处Session [“Username”]为空

n web.config中的代码很简单。我尝试使用

  

sessionState timeout =“2”

n

  

mode =“InProc”和“StateServer”

2 个答案:

答案 0 :(得分:1)

最常见的原因是cookie被禁用。您需要使用cookie,或切换到无Cookie会话模型,这有点难以使用。参考这个

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q316112

答案 1 :(得分:0)

旧的,但我遇到了类似的问题。 确保您的iis中没有使用Web园设置。换句话说,检查您的应用程序池是否包含多个工作进程(这是默认值)。

应用程序池 - >高级设置 - >最大工作进程

enter image description here

相关问题