asp.net-mvc – User.Identity.IsAuthenticated在设置cookie并进
我对MVC4用户授权有问题。
System.Web.Security.Membership.ValidateUser返回true。 [AllowAnonymous] [HttpPost] public ActionResult Login(LoginModel model,string returnUrl) { if (ModelState.IsValid) { if (System.Web.Security.Membership.ValidateUser(model.UserName,model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName,model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index","Home"); } } else { ModelState.AddModelError("","The user name or password provided is incorrect."); } } // If we got this far,something failed,redisplay form return View(model); } 解决方法
在调用FormsAuthentication.SetAuthCookie()之后,下一个请求之前,User.Identity.IsAuthenticated不会被设置为true。
见http://msdn.microsoft.com/en-us/library/twk5762b.aspx
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 要监控已部署的ASP.NET Web应用程序的关键性能指标是什么?
- 如何在ASP.NET中为不同的URL设置不同的超时
- asp.net-mvc – Razor视图中没有渲染的条件ActionLink(asp.
- asp.net-mvc – 使用ui-router的.NET MVC和Angular
- 什么是ASP.NET应用程序部署的最佳实践
- 当我使用ASP.NET传输文件时,为什么IIS7会忽略我的内容类型标
- asp.net-mvc – 了解nopCommerce的MVC标签
- asp.net – 使CustomValidator与ValidationSummary消息框一
- asp.net-core – asp.net核心自定义模型绑定器,仅适用于一个
- 没有业务逻辑层的ASP.Net 2.0应用程序?
- asp.net-core – userManager.FindByName不返回角
- asp.net-web-api – 如何从WEB API检索邮件?
- asp.net-mvc – 将集合传递给EditorFor()时,它会
- 如何利用ETW(Event Tracing for Windows)记录日
- asp.net-mvc – 使用Asp.Net Mvc进行AngularJs路
- asp.net-core – 通过JWT Token授权
- asp.net – 从Global.asax中获取操作的绝对URL路
- asp.net-mvc-4 – 为什么一些Asp.Net MVC4模板需
- rest – asp.net Web Api – 默认错误消息
- asp.net-mvc-3 – .NET 4.0 MEF.可插入的ASP.NET