RazorKillBen
RazorKillBen

Reputation: 573

ASP.Net Azure Web Application authentication redirecting to domain instead of localhost

I have two Azure hosted web applications. The first one seems to work correctly - when running the app on localhost for testing and development, upon authentication, it redirects back to localhost and the app works fine. When published, it instead redirects to the domain and works just fine too.

I have setup a second webapp in the exact same way - the web.config seems to be the same and the application is configured the same on Azure. When running published, it works fine, but on localhosst, it wants to redirect upon authentication to the domain, which then reauthenticates again and finally logs in to the domain - not the localhost version.

I have scoured all the settings and cannot see any differences. More bizarrely, the 1st web app seems to be configured on Azure to only have one reply URL of the domain; there is no reference to localhost anywhere so it must be doing this from within the app.

How can I achieve the two "versions" in a webapp with Azure?

Upvotes: 1

Views: 1122

Answers (1)

alphaz18
alphaz18

Reputation: 2766

What you are saying doesn't make too much sense to me with what is supposed to happen. But anyway, if you want a localhost and published version both working with the same app registration, you would normally just set up multiple reply urls. then in the app configuration, eg the authentication request from the app, you generally will tell it what redirect/reply url you want the app to send back to after auth.

Ultimately in the uri generated to log in there will be a redirect_uri param that you will send with the request asking for a specific reply url. how you set it depends on how you are authenticating, msal, library etc. see here for some examples https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-sign-user-app-configuration?tabs=aspnet in .net core, the library auto determines the front part of url so you just give it the relative path of redirect url in the callbackpath parameter, doing it this way allows you to use the same code for both localhost and published. But in asp.net example you have to provide the entire redirect_url, which probably means you need to change it or have a different config file for local vs published.

Upvotes: 1

Related Questions