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

问题描述 投票:2回答:2

我有一个登录页面,我在登录时重定向到另一个页面。我在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”

ñ

mode =“InProc”和“StateServer”

asp.net session web-config session-variables response.redirect
2个回答
1
投票

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

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


0
投票

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

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.