0
votes

IIS 7 running an ASP.NET MVC 4 application. I have enabled Basic Authentication in IIS for the website, and disabled all other authentication types. When the user reaches the site, they are presented with the auth challenge popup, which they use their domain credentials to authenticate.

However, after successful authentication, they are being redirected to `/login.aspx?ReturnURL=originalPath.

Ideally, I would like the redirect to send them back to the original requested URL. How might I do that?

To be more specific about what I am trying to accomplish, we have an internal NuGet feed running at http://nuger.ourdomain.com/nuget. NuGet supports basic authentication. However, my nuget.exe install commands are failing due to this bad redirect. e.g.

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

I can see this behavior directly if I browse to https://nuget.ourdomain.com/nuget in my browser -- I get the auth challenge, then redirects to /login.aspx?ReturnUrl=%2fnuget. At that point, if I manually go to my original target URL, it loads fine.

With basic auth there a way to get the proper redirect back to the original request url?

1

1 Answers

1
votes

Turns out ASP.NET MVC enabled forms authentication by default, so even though I did not have it enabled in IIS, nor an entry for it in my web.config, it was still being used. I had to add the following to my web.config:

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

And then it stopped redirecting to login.aspx. And, bonus, it seems to be agreeable to NuGet!