I about to host an existing ASP.NET MVC app running on .NET 4.8 in Azure. I want to implement authentication using Azure AD (Azure Identity).
I am looking for some quickstart or walk-through but can't find what I used to find just a year ago. Can someone help me steps so I can enable my app to use Azure AD authentication?
Thanks
I used the code below to implement AzureAD for ASP.NET MVC .NET 4.8 app.
I created an Account Controller in the controller folder, as shown below.
AccountController:
I added the Startup.Auth.cs class to my App_Start folder.
App_Start/Startup.Auth.cs:
I created an app registration in my Azure account, as shown below:
I added ClientId, TenantId, and dependentAssembly to the web.config, as shown below.
web.config:
I added a Startup.cs class to the root directory.
Startup.cs:
Then, I implemented the _loginPartial.cshtml view in the Shared folder, as shown below.
Shared/_LoginPartial.cshtml:
I added the signoutcallback.cshtml view to the Account folder in the View folder for sign-out purposes.
View/Account/SignOutCallback.cshtml:
I added the
[Authorize]attribute to my controller, as shown below.HomeController:
This is my Package.config, I downloaded the required NuGet packages, as shown below.
package.config:
I added a Redirect URL to the App Registration,
https://localhost:Port/signin-oidcas shown below:After running the app, it asked me to pick an account, as shown below:
It asked me to accept the app registration.
OutPut:
Before publishing your app to Azure, change the PostLogoutRedirectUri value to
https://<AzureWebAppName>.azurewebsites.net/.auth/login/aad/callbackin web.config.I added an Identity provider in the Azure Web app as shown below:
I selected the Identity Provider as Microsoft and added my app registration.
It was added to the web app successfully, as shown below:
Then, I added the Redirect URI
https://<WebAppName>.azurewebsites.net/.auth/login/aad/callbackto my App Registration.Azure App Service Output: