在成功登录后,我对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); } }
登录后,it RedirectToAction(" MyProfile ","MyAccount");但在MyProfile视图中,我看不到任何关于用户的信息,我无法使用授权访问contac页面
-Contact控制器
[Authorize] public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); }
发布于 2015-09-10 06:21:44
我在登录控制中通过会话进行了测试,它运行得很好:
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);
Session["loginname"] = user.Employee.FirstName;
if (Url.IsLocalUrl(ReturnUrl))
{
return Redirect(ReturnUrl);
}
else
{
return RedirectToAction("MyProfile", "MyAccount");
}
}我可以从数据库获取视图中的会话“loginname”。
https://stackoverflow.com/questions/32493253
复制相似问题