asp.net-mvc-5 – MVC 5表单身份验证为User.Identity.Name返回nu
发布时间:2020-12-16 06:38:44 所属栏目:asp.Net 来源:网络整理
导读:身份验证无法在我的MVC 5应用程序中进行表单身份验证身份验证.页面被正确重定向,但User.Identity.IsAuthenticated和User.Identity.Name值为空. 我的webconfig, system.web authentication mode="Forms" forms cookieless="UseCookies" defaultUrl="~/" login
身份验证无法在我的MVC 5应用程序中进行表单身份验证身份验证.页面被正确重定向,但User.Identity.IsAuthenticated和User.Identity.Name值为空.
我的webconfig, <system.web> <authentication mode="Forms"> <forms cookieless="UseCookies" defaultUrl="~/" loginUrl="~/user/signin" name="MYAPPWeb" timeout="21600" slidingExpiration="true"/> </authentication> UserController的, [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult SignIn(SignInViewModel user) { UserDTO userObj; using (var services = new ServiceFactory()) { userObj = services.UserManagement.ValidateLoginDetails(ConfigHelper.EnvironmentString,user.TenantName,user.Username,user.Password); } string userID = userObj.UserID.ToString(); //FormsAuthentication.RedirectFromLoginPage(userID,user.RememberMe); FormsAuthentication.SetAuthCookie(userID.ToString(),true); FormsAuthentication.RedirectFromLoginPage(userID,false); //DO NOT REMEMBER ME } HomeController(默认页面) public ActionResult Index() { bool x = User.Identity.IsAuthenticated; //false? string y = User.Identity.Name; //null? return View(); } 它看起来很直接,我错过了什么?请帮忙! 注意: <add key="owin:AutomaticAppStartup" value="false"/> 解决方法
如果您的项目默认情况下具有Owin身份验证,则它将从项目中删除表单身份验证.
如果您看到您的网络配置,您可能会看到 <remove name="FormsAuthentication" /> 组态. 只需删除它. 我有同样的问题,它解决了这个问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – CssRewriteUrlTransform没有被调用
- ASP.NET Core框架揭秘(持续更新中…)
- asp.net – Web Forms MVP项目有哪些好的资源?
- asp.net服务器控件中的默认值
- asp.net-mvc – 是否有PRG模式的名称,在验证失败时没有重定
- asp.net – 如何将CssClass应用于DataGrid HyperLinkColumn
- asp.net-mvc – MVC5中的Bundle.IncludeDirectory输出错误的
- asp.net-mvc – MVC Tag助手无法正常工作
- asp.net-mvc – 可以为MVC Razor Layout指定可搜索的位置格
- asp.net-mvc – ASP.NET MVC和ViewState
推荐文章
站长推荐
- asp.net-core – ASP.NET 5中的HandleUnknownAct
- Asp.net Razor,语法错误 – onclick事件参数
- asp.net-mvc – Azure托管的ASP.NET MVC网站删除
- 使用ApplicationHost.CreateApplicationHost()创
- ASP.NET MVC Web API2 AngularJS授权和身份验证
- 下载 – 使用ASP.Net Webapi流式传输大图像
- asp.net-mvc – 每个验证属性的所有不显眼的验证
- ASP.NET核心项目:如何防止编写原型
- 如何使用ASP.net Web API和Javascript下载二进制
- 详解 ASP.NET Core MVC 的设计模式
热点阅读