【发布时间】:2017-11-02 03:19:36
【问题描述】:
我尝试添加会话,然后我在重定向后访问另一个页面,这总是显示为空
Session.Add("pUser_Name", ds_1.Tables[0].Rows[0]["User_Name"].ToString());
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Redirect("DashBoard.aspx", false);
在我正在访问的另一个页面上
protected void Page_Load(object sender, EventArgs e)
{
if (Session["pUser_Name"] == null) ////here is error NULL
{
Response.Redirect("Admin.aspx");
}
}
我试过了
protected override void OnInit(EventArgs e)
{
if (Session["pUser_Name"] == null)
{
Response.Redirect("Admin.aspx");
}
base.OnInit(e);
}
还有
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DashBoard.aspx.cs" Inherits="SC.DashBoard" EnableTheming="true"
Theme="Theme1" EnableSessionState="True" %>
和为会话分配值的管理页面
<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="True" CodeBehind="Admin.aspx.cs" Inherits="SC.Admin" %>
和 web.config 文件
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<sessionState timeout="12000"/>
</system.web>
但仍然面临同一个会话是空的
【问题讨论】:
-
只是为了尝试而不是
Session.Add使用HttpContext.Current.Session.Add并像HttpContext.Current.Session["pUser_Name"]一样访问 -
同样的问题仍未解决
-
更新面板也无法解决问题..
-
明确一点,什么是空?是 Session 还是 Session["pUser_name"]?
-
请注意,如果您的页面是通过从外部网关或应用程序返回和回调加载的,则它具有不同的请求者和不同的会话 ID