asp.net-mvc – Microsoft.Owin.Security.IAuthenticationManager
|
我在我的应用程序中使用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-mvc – 用于选择的KendoUI网格Ajax绑定参数
- asp.net-mvc – Bug? ASP.NET MVC 2中的客户端验证导致Val
- asp.net-mvc-2 – 为MVC2 AsyncControllers构建单元测试
- asp.net-web-api – WebApi DelegatingHandler未调用prefli
- asp.net-identity – 为什么一个站点的ASP.NET身份登录可以
- asp.net-mvc – ASP.Net WebAPI区域支持
- asp.net-mvc – 什么可能导致一个503服务不适用于asp.net m
- asp.net-mvc – 使用ASP.NET MVC测试驱动的开发 – 从哪里开
- asp.net-mvc – 如何手动创建简单的成员资格sql表?
- asp.net-mvc-3 – mvc3 – 如何从源代码禁用符号的htmlenco
- ASP.NET ListView – 渲染THEAD / TBODY标签
- asp.net-mvc – 如何在一个视图中使用两个IENume
- 如何在asp.net MVC 3中获取当前的视图名称?
- asp.net-mvc – 如何在ASP MVC中自定义Html.Vali
- asp.net-mvc – ASP.NET MVC 3 Beta 1 Block访问
- ASP.NET MVC 3数据注释大于下载日期时间和int
- asp.net-mvc – 如何删除SimpleMembership用户?
- asp.net-ajax – ASP.Net AJAX UpdatePanel无法触
- asp.net-mvc – ASP.NET MVC中的Razor页面生命周
- httphandler – AjaxToolkit IIS7 Asp.Net 4.0:
