判断用户是否登录,获取用户的customerID

public static string GetShoppingCartID()
{
HttpContext hc = HttpContext.Current;
//如果有登录ID就返回登录ID
if (!string.IsNullOrEmpty(hc.User.Identity.Name))
{
return hc.User.Identity.Name;
}

//如果有临时ID就返回临时ID
if (hc.Request.Cookies["Customer"] != null)
{
return hc.Request.Cookies["Customer"].Value;
}
else //创建一个临时ID
{
string tempid=Guid.NewGuid().ToString();
hc.Response.Cookies["Customer"].Value = tempid;

return tempid;
}
}

posted @ 2017-12-06 13:39  -小打小闹小幸福ζ  阅读(434)  评论(0编辑  收藏  举报