【发布时间】:2016-02-01 15:39:33
【问题描述】:
我有一个 ASP.NET 4.6 WebForms 应用程序,它利用 Identity 2.1 包进行注册和身份验证系统。它使用 Owin 身份验证,而不是 Forms 或 Windows。
我的尝试是不允许匿名用户查看网站的任何页面并将他们重定向到登录页面。这就是为什么我在我的 Web.config 中添加了以下内容(根据 this article):
<system.web>
<authorization>
<deny users="?"/>
</authorization>
<authentication mode="None" />
</system.web>
<location path="~/Account/Login.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
从那时起,我在浏览器中运行应用程序时总是会出现重定向循环。我为 MVC 找到了不同的解决方案,但没有为 WebForms 找到。
可能是什么原因以及如何消除它?
这是我在 Startup.Auth.cs 文件中的配置方法:
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login.aspx"),
CookieSecure = CookieSecureOption.Always,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
}
【问题讨论】:
-
我最近也有类似的情况。我的登录屏幕在页面加载方法中有一个注销方法。注销调用重定向到注销页面。这导致了一个循环。
标签: asp.net redirect webforms asp.net-identity owin