在ASP.NET页面获取不到Session值。
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呢?