【问题标题】:How to redirect to original request after an HTTP Challenge on IIS?如何在 IIS 上的 HTTP 质询后重定向到原始请求?
【发布时间】:2014-01-03 20:21:51
【问题描述】:

IIS 7 运行 ASP.NET MVC 4 应用程序。我在 IIS 中为网站启用了基本身份验证,并禁用了所有其他身份验证类型。当用户到达该站点时,他们会看到身份验证挑战弹出窗口,他们使用其域凭据进行身份验证。

但是,在成功验证后,它们将被重定向到 `/login.aspx?ReturnURL=originalPath。

理想情况下,我希望重定向将它们发送回原始请求的 URL。我该怎么做?

为了更具体地说明我要完成的工作,我们在http://nuger.ourdomain.com/nuget 运行了一个内部 NuGet 提要。 NuGet 支持基本身份验证。但是,由于这种错误的重定向,我的 nuget.exe install 命令失败了。例如

https://nuget.ourdomain.com/nuget -> password challenge
-> redirects to https://nuget.ourdomain.com/login.aspx?ReturnUrl=%2fnuget
-> Returns 404 Not Found because there is no login.aspx on this MVC app
-> NuGet sees the 404 and sees that something failed, 
   so prompts for passsword again, ad infinitum

如果我在浏览器中浏览到https://nuget.ourdomain.com/nuget,我可以直接看到这种行为——我收到了身份验证挑战,然后重定向到/login.aspx?ReturnUrl=%2fnuget。那时,如果我手动转到我的原始目标 URL,它会正常加载。

使用基本身份验证有办法将正确的重定向返回到原始请求 url?

【问题讨论】:

    标签: asp.net-mvc iis iis-7 nuget basic-authentication


    【解决方案1】:

    原来 ASP.NET MVC 默认启用了表单身份验证,所以即使我没有在 IIS 中启用它,也没有在我的 web.config 中为其添加条目,它仍然被使用。我必须在我的 web.config 中添加以下内容:

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="FormsAuthentication" />
        </modules>
    <system.webServer>
    

    然后它停止重定向到 login.aspx。而且,奖金,它似乎对 NuGet 很满意!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多