我一直在这里挠我的头一阵子,但仍然无法得到它。 我试图简单地在MVC2应用程序中登录用户。无法在MVC中登录用户!
我已经试过,我知道去尝试,但仍无法弄清我做错了一切。 以下是我已经尝试了几件事情:
FormsAuthentication.SetAuthCookie(emailAddress, rememberMe);
var cookie = FormsAuthentication.GetAuthCookie(emailAddress, rememberMe);
HttpContext.Response.Cookies.Add(cookie);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(emailAddress, rememberMe, 15);
FormsIdentity identity = new FormsIdentity(ticket);
GenericPrincipal principal = new GenericPrincipal(identity, new string[0]);
HttpContext.User = principal;
我不知道是否有任何这是做(因为它不工作)了正确的事情。 经过设定HttpContext.User = principal
然后Request.IsAuthenticated == true
。 然而,在Global.asax中我有这样的:
HttpCookie authenCookie = Context.Request.Cookies.Get(
FormsAuthentication.FormsCookieName);
有史以来唯一可用的饼干是ASPNET会话cookie。
任何想法都将非常感激!
你是说新的默认ASP.NET MVC 2项目不起作用?如果没有,您是否尝试过使用默认项目来查看是否有效? – Eilon 2010-01-07 04:42:47
默认的mvc2项目确实有效。我不知道我是如何搞砸的! – devlife 2010-01-07 05:12:01