Asp.net mvc Asp.net MVC会话到Cookie
目前我正在使用会话来控制我的应用程序,我现在将使用cookies,但我的问题是关于我使用的CRUD var user_code=Convert.ToInt32(HttpContext.Current.Session[“userId]”);Asp.net mvc Asp.net MVC会话到Cookie,asp.net-mvc,Asp.net Mvc,目前我正在使用会话来控制我的应用程序,我现在将使用cookies,但我的问题是关于我使用的CRUD var user_code=Convert.ToInt32(HttpContext.Current.Session[“userId]”); 要在我的数据库中持久化我的用户和Cookie,该如何做?当您将值分配给会话时,您可以将其分配给Cookie。 为了安全起见,用户以加密格式登录时需要添加cookie 创建Cookie的代码 用于从Cookie中读取值的代码 注销时,您需要删除您创建的此cook
要在我的数据库中持久化我的用户和Cookie,该如何做?当您将值分配给会话时,您可以将其分配给Cookie。 为了安全起见,用户以加密格式登录时需要添加cookie 创建Cookie的代码 用于从Cookie中读取值的代码 注销时,您需要删除您创建的此cookie
if ( Request.Cookies["userId"] != null )
{
var c = new HttpCookie( "userId" );
c.Expires = DateTime.Now.AddDays( -1 );
Response.Cookies.Add( c );
}
您不应该使用
会话
。建议您花一些时间了解在MVCI am中使用FormsAuthenticationTicket的基本知识,因为要保存我的角色。在FormsAuthenticationTicket上使用2 cookie或存在任何问题吗?
var cookie = Request.Cookies["userId"];
if (cookie != null)
{
var value = cookie.Value;
// TODO: do something with the value
}
if ( Request.Cookies["userId"] != null )
{
var c = new HttpCookie( "userId" );
c.Expires = DateTime.Now.AddDays( -1 );
Response.Cookies.Add( c );
}