I need to access UserId from all my asp.net mvc application in order to use it for hiding/show some elements:
the UserId the Primary Key in user tables (in SQL server).
in normal asp.net I have used a BasePage:Page and added:
public long FinKaynUserId
{
//long FinKaynUserId = 0;
get
{
if (HttpContext.Current.Session["FinKaynUserId"] != null && Convert.ToInt64(HttpContext.Current.Session["FinKaynUserId"]) != 0)
return Convert.ToInt64(HttpContext.Current.Session["FinKaynUserId"]);
else
{
HttpCookie myCookie = HttpContext.Current.Request.Cookies["FinKaynUserId"];
if (myCookie != null)
{
HttpContext.Current.Session["FinKaynUserId"] = Convert.ToInt64(myCookie.Value);
// Session["User"] = (new UserManager()).GetUser(Convert.ToInt64(Session["UserId"]));
return Convert.ToInt64(HttpContext.Current.Session["FinKaynUserId"]);
}
else
return 0;
}
}
set
{
HttpCookie cookie = new HttpCookie("FinKaynUserId");
cookie.Value = value.ToString();
cookie.Secure = false;
cookie.Expires = DateTime.Now.AddDays(3);
HttpContext.Current.Request.Cookies.Add(cookie);
HttpContext.Current.Session["FinKaynUserId"] = value;
}
}
How can i do the same thing in asp.net mvc.
emailaddressoruseridand then retrieve stored ticket (key) usingUser.Identity.Name