【发布时间】:2015-12-06 05:33:18
【问题描述】:
我遇到了 MVC 5 身份验证问题 登录成功后,我想我无法保存 UseCookieAuthentication。
- 我的启动代码:
public partial class Startup { public void Configuration(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/MyAccount/Login") }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); } }
-
我的登录控制器:
public ActionResult Login(Login l, string ReturnUrl="") { using (CBDB2012Entities dc = new CBDB2012Entities()) { var user = dc.Users.Where(a => a.UserName.Equals(l.Username) && a.Password.Equals(l.Password)).FirstOrDefault(); if (user != null) { FormsAuthentication.SetAuthCookie(user.UserName, l.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return Redirect(ReturnUrl); } else { return RedirectToAction("MyProfile", "MyAccount"); } } } ModelState.Remove("Password"); return View(); }
登录后,它 RedirectToAction("MyProfile", "MyAccount"); 但在 MyProfile 视图中,我看不到有关用户的任何信息,也无法使用 [Authorize] 访问联系页面:
-联系人控制器
[Authorize] public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); }
【问题讨论】:
标签: authentication asp.net-mvc-5