首页 文章

Owin Authentication创建重定向循环

提问于
浏览
2

我有一个ASP.NET 4.6 WebForms应用程序,它利用Identity 2.1包进行注册和身份验证系统 . 它使用 Owin authentication ,而不是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文件中的Configuration方法:

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))
            }
        });
    }

4 回答

  • 0

    将身份验证模式设置为“forms”并将服务器上的身份验证设置为Formsauthentication&Anonymous .

    等等我寻找另一种解决方案:)

  • 0
    <authentication mode="Forms" />
            <authorization>
                <allow users="*" />
            </authorization>
    
    
    
    
    
    
    
    <system.webServer>
        <modules>
            <remove name="FormsAuthentication" />
        </modules>
    </system.webServer>
    

    并删除“ <deny users="?"/> ”行

  • 0

    改变位置路径

    <location path="~/Account/Login.aspx">
    

    <location path="Account/Login.aspx">
    

    并删除友好的网址

  • 0

    将此XML添加到Accounts / Web.Config

    <system.web>
         <authorization>
             <allow users="*"/>
        </authorization>
    </system.web>
    

    这解决了我的问题 .

    请注意,这是Accounts文件夹中的Web.Config

相关问题