在MVC中发生Setcookie异常? [英] Setcookie exception occurring in MVC?
本文介绍了在MVC中发生Setcookie异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究MVC 5,我在登录后尝试设置cookie。然后发生了错误。
错误:HTTP标头发送后,服务器无法附加cookie。
请帮助我...
我尝试过的事情:
< pre lang =c#> HttpCookie authcookie = new HttpCookie( _Auth,Constants.token);
HttpCookie usernameCookie = new HttpCookie( _ username ,用户名);
Response.SetCookie(authcookie);
Response.SetCookie(usernameCookie);
解决方案
我写了,
if (filterContext.HttpContext.Request.Cookies [ _ Auth]!= null )
{
}
然后,问题解决了。
I am working on MVC 5, there I am trying to set cookie after login. then error occurred.
Error: Server cannot append cookies after HTTP headers have been sent.
Please help me...
What I have tried:
HttpCookie authcookie = new HttpCookie("_Auth", Constants.token);
HttpCookie usernameCookie = new HttpCookie("_username", username);
Response.SetCookie(authcookie);
Response.SetCookie(usernameCookie);
解决方案
Hi,
I did write,
if (filterContext.HttpContext.Request.Cookies["_Auth"] != null) { }
Then, the issue solved.
这篇关于在MVC中发生Setcookie异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文