Skip to main content

Back-End Development

Configuring Web.config to Redirect to Azure Website Instead of Localhost

Hands typing at keyboard

If you have created your App Service on Azure but it redirects to a localhost instead of the Azure website URL upon authentication, there are some changes you will have to make in your Web.config file. In our example, we will be using Microsoft.Owin.Security.OpenIdConnect library for authentication (Azure AD).

We are using .NET Framework 4.7.2 in our project. Ensure that the version in the App Service aligns with that of the project.B5 P1

The redirect issue is occurring because Azure Active Directory simply does not know where to send the user back to upon authentication. To resolve this issue, we simply have to manually add the RedirectUri configuration value in Web.Config and include that in the OpenIdConnectAuthenticationOptions! Note RedirectUri is different from PostLogoutRedirectUri.

 

Add the RedirectUri key with the azure website URL as its value.

B5 P2

In case you forgot, ClientID and TenantID can be found under AAD > App registrations > Corresponding Web App.B5 P3

Call RedirectUri in the Startup.Auth.cs file using ConfigurationManager and store the value in the _redirectUri variable.B5 P4

Add the RedirectUri to the OpenIdConnectAuthenticationOptions.B5 P5

There should be many reasons why this has to be manually configured but for my case, I am assuming this happened because I already had an Active Directory set up within the project before creating the App Service. I will include a documentation from Microsoft here that helped me understand the sign-in process.

 

Hope that helped!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

David Hwang

David Hwang is an Associate Technical Consultant in the Sitecore/Microsoft Business Unit. He will be blogging about various concepts in technologies for beginners.

More from this Author

Follow Us