asp.net-mvc – Microsoft.Owin.Security.IAuthenticationManage
发布时间:2020-12-15 20:50:32 所属栏目:asp.Net 来源:网络整理
导读:我在我的应用程序中使用Microsoft.Owin.Security(.NET 4.5上的ASP.NET MVC v 5.2.0).但只是OWIN的安全部分没有别的.当用户想要访问本地受保护的URL时,请求将被重定向到登录页面.但是当我在服务器上发布应用程序时,我得到这个窗口而不是重定向: 我的登录和注
我在我的应用程序中使用Microsoft.Owin.Security(.NET 4.5上的ASP.NET MVC v 5.2.0).但只是OWIN的安全部分没有别的.当用户想要访问本地受保护的URL时,请求将被重定向到登录页面.但是当我在服务器上发布应用程序时,我得到这个窗口而不是重定向:
我的登录和注销方法是: public void LogIn(long userId,string username,string email,bool persistent) { var claims = new List<Claim>{ new Claim(ClaimTypes.NameIdentifier,userId.ToString(CultureInfo.InvariantCulture)),new Claim(ClaimTypes.Name,username),new Claim(ClaimTypes.Email,email),new Claim(ClaimTypes.IsPersistent,persistent.ToString()) }; var id = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie); var ctx = HttpContext.Current.Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = persistent },id); } public void LogOut() { var ctx = HttpContext.Current.Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignOut(); } 这是我的创业公司: public partial class Startup { public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/account/log-in/"),AuthenticationMode = AuthenticationMode.Active,CookieHttpOnly = true,CookieName = ".some-cookie-name",ExpireTimeSpan = TimeSpan.FromDays(1),LogoutPath = new PathString("/account/log-out/"),SlidingExpiration = true,ReturnUrlParameter = "continue" }); } } 我在global.asax :: Application_Start方法中也有这一行: AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; 和web.config中的这些配置: <system.web> <authentication mode="None" /> <httpModules> <remove name="FormsAuthenticationModule" /> <remove name="RoleManager" /> </httpModules> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="false"> <remove name="FormsAuthenticationModule" /> <remove name="RoleManager" /> </modules> </system.webServer> 最后我在使用IIS 7.5的Windows 2008 R2计算机上运行该应用程序.您知道我应该怎样做才能使OWIN在我的服务器上正常工作,就像我的本地一样? 更新:要明确: 假设我有这些行动: [AllowAnonymous] public ActionResult AnonymousAction() { } [Authorize] public ActionResult UsersAction() { } 一个用于匿名用户,另一个用于登录用户(具有良好的属性装饰).匿名用户可以轻松访问AnonymousAction而不会出现任何错误或错误行为.但是当他们(我的意思是匿名用户)想要访问UsersAction时,他们将看到我上面提到的窗口而不是被重定向到登录页面. 解决方法
与Erik说的一样,您的IIS设置不正确,很可能是未正确配置身份验证.
转到IIS,选择您的站点,然后选择“身份验证”部分.它应该如下所示: 确保已启用匿名身份验证,并禁用其他所有内容. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – MS Chart控件创建的临时文件应该放在哪里?
- asp.net – IIS 7.0和IIS 7.5之间有什么区别?
- asp.net – 使用itemtemplate动态地将列添加到Grid-view
- asp.net – Html-Agility-Pack没有加载包含完整内容的页面?
- ASP.NET Core WebAPI 实现CRUD
- asp.net core系列 49 Identity 授权(上)
- asp.net-mvc – 在ASP.NET MVC 2中模板化Html.DisplayFor()
- 在asp.net中缓存sql server数据,直到修改行为止
- asp.net-mvc – mvc razor @helper可以返回非编码标签吗?
- asp.net – 突然收到“无法向会话状态服务器发出会话状态请