在ASP.NET页面获取不到Session值。

foxriver1205 foxriver1205 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Sessions.LoginName = cusName;
Sessions.CustomerID = Convert.ToInt32(ds.Tables[0].Rows[0]["PKID"]);
public static class Sessions
{
private static HttpContext CurrContext
{
get { return HttpContext.Current; }
}

/// <summary>
/// 用户登陆后的用户ID,0表示没有登陆
/// </summary>
public static int CustomerID
{
get
{
try
{ return CurrContext.Session["CustomerID"] == null ? 0 : Convert.ToInt32(CurrContext.Session["CustomerID"]); }
catch
{ return 0; }
}
set
{ CurrContext.Session["CustomerID"] = value; }
}

/// <summary>
/// 用户登陆后的用户登录名,""表示没有登陆
/// </summary>
public static string LoginName
{
get
{
return CurrContext.Session["LoginName"] == null ? "" : CurrContext.Session["LoginName"].ToString().Trim();
}
set
{ CurrContext.Session["LoginName"] = value; }
}
}

if (!Page.IsPostBack)
{
if (Sessions.LoginName.ToString() == "")
{
Response.Redirect(Request.ApplicationPath.ToString() + "index.aspx", true);
}
else
{
int pkid = Convert.ToInt32(Sessions.CustomerID.ToString());
FillInfo(pkid);
}
}
代码如上:为什么我在另一个页面(从登录页面跳转过去的页面)获取不到Sessions.LoginName呢?
...全文
评论 24
收藏 已收藏
分享
返回顶部
foxriver1205
.NET社区 62,272 成员 668,968 内容