/// <summary>
/// 用户是否登录
/// </summary>
public static bool UserIsLogin
{
get
{
if (HttpContext.Current.Session["B2CRegUserName"] == null)
return false;
return true;
}
}
/// <summary>
/// 用户退出
/// </summary>
public static void LogonOut()
{
if (HttpContext.Current.Session["B2CRegUserName"] != null)
{
HttpContext.Current.Session["B2CRegUserName"] = null;
}
if (HttpContext.Current.Response.Cookies["B2CRegUserName"] != null)
{
HttpContext.Current.Response.Cookies["B2CRegUserName"].Value = "";
}
if (HttpContext.Current.Session["B2CUserType"] != null)
{
HttpContext.Current.Session["B2CUserType"] = null;
}
}
/// <summary>
/// 添加Session["B2CUserRegName"]
/// </summary>
/// <param name="username"></param>
/// <param name="usertype"></param>
public static void AddUserToSession(string username, string usertype)
{
if (false == UserIsLogin)
{
HttpContext.Current.Session["B2CRegUserName"] = username;
HttpContext.Current.Session["B2CUserType"] = usertype;
}
else
{
if (!UserNameOfSession.Equals(username))
{
HttpContext.Current.Response.Cookies["B2CRegUserName"].Value = username;
HttpContext.Current.Response.Cookies["B2CRegUserName"].Domain =
ConfigurationManager.AppSettings["B2CDomain"];
HttpContext.Current.Response.Cookies["B2CRegUserName"].Expires = DateTime.Now.AddDays(1);
HttpContext.Current.Session["B2CRegUserName"] = username;
HttpContext.Current.Session["B2CUserType"] = usertype;
}
}
}
/// <summary>
/// 获取Session中的UserName值
/// </summary>
public static string UserNameOfSession
{
get
{
if (HttpContext.Current.Session["B2CRegUserName"] != null)
return HttpContext.Current.Session["B2CRegUserName"].ToString();
return "";
}
}
/// <summary>
/// 获取Session中的UserType值
/// </summary>
public static string UserTypeOfSession
{
get
{
if (HttpContext.Current.Session["B2CUserType"] != null)
return HttpContext.Current.Session["B2CUserType"].ToString();
return "";
}
}