繁体   English   中英

在IIS上进行HTTP质询后,如何重定向到原始请求?

[英]How to redirect to original request after an HTTP Challenge on IIS?

运行ASP.NET MVC 4应用程序的IIS 7。 我已经在IIS中为网站启用了基本身份验证,并禁用了所有其他身份验证类型。 当用户到达站点时,将向他们显示auth质询弹出窗口,他们使用其域凭据进行身份验证。

但是,在成功通过身份验证之后,它们将被重定向到`/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中启用它,也没有在我的web.config中启用它的条目,它仍在使用。 我必须将以下内容添加到我的web.config中:

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

然后它停止重定向到login.aspx。 而且,奖金,似乎对NuGet来说是可以接受的!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM