[英]Showing last cookie value on Relogin (i.e. Again login after logout) in Asp.net MVC with Razor
I am working on Asp.net MVC with Razor view engine with C#. 我正在使用带有C#的Razor视图引擎来开发Asp.net MVC。 I have a login form and on login I create a Cookie for userid, and on logout I remove this cookie evrything works fine yet. 我有一个登录表单,登录后为用户ID创建一个Cookie,并在注销时删除了该cookie evrything效果还不错。 but the problem starts when I Login again it still shows the value of Previous Login's userid. 但是问题是在我再次登录时开始的,它仍然显示以前登录用户名的值。
The code of creating cookie is 创建cookie的代码是
HttpCookie newCookie = new HttpCookie(cookieId, cookieValue);
newCookie.Expires = DateTime.Today.AddDays(30);
HttpContext.Current.Response.Cookies.Add(newCookie);
And to remove cookie 并删除cookie
if (HttpContext.Current.Request.Cookies[cookieId] != null)
{
HttpContext.Current.Response.Cookies[cookieId].Value = null;
}
I have remove the cookie on login if there exist but still it is not working , please help me...... 我已经删除了登录时的cookie(如果存在),但仍然无法正常工作,请帮助我......
You can remove your cookie like below, 您可以按照以下方式删除Cookie,
if ( Request.Cookies["MyCookie"] != null )
{
var c = new HttpCookie( "MyCookie" );
c.Expires = DateTime.Now.AddDays( -1 );
Response.Cookies.Add( c );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.