Developing ASP.NET Apps With Azure Active Directory

In this article, we will see how to authorize our MVC application using Azure Active Directory and we will learn how to create an ASP.NET application that is configured for sign- on with Azure Active Directory (Azure AD).

  • Concept
  • Implementation – Creating Azure Active Directory in Azure.
  • Implementation – Connect Azure Active Directory with your MVC Application.

Concept:

About

Nowadays, authentication is quite simple as compared to previous times. We used to Save to db and get credentials from the db and it would authenticate accordingly. But now there's no need to save into db. Azure active directory enables authentication for your web application which is hosted on Azure. You can just use Azure Authentication to authenticate users from your organization or any other custom azure active directory domain.

Implementation – Creating Azure Active Directory in Azure.

  • Sign in to Azure Management portal or classic portal.
  • Click on Active Directory which is located in left panel.
  • Click on Default Directory.

    Azure active directory

  • Click on Users Tab at the top of the page.
  • Then click on Add User as highlighted below.

    Azure active directory
  • Select new user give username.

    Azure active directory
  • Enter the first name, last name and display name and set the role.

    Azure active directory
  • A temporary password will be created for the new user and displayed in dialog.

    Azure active directory
  • Save the password, you will need this password after your first log in so save it to notepad. The below image shows the new admin account. You can use Azure Active directory to log into your app, not the Microsoft account as shown below.

    Azure active directory

Implementation – Connect Azure Active Directory with your Mvc Application.

  • Open Visual Studio, click File - New
  • Select Visual C# Web Project from the left panel and then click on Ok.

    Azure active directory
  • Uncheck the Add Application Insights to project if you don’t want the functionality for your application.
  • In this New NET Project dialog, select MVC, and then click Change Authentication.

    Azure active directory
  • In Change Authentication Dialog, select Work and School Accounts.

    These options are very helpful to automatically register your application with Azure AD and it helps you to automatically configure your application to integrate with Azure AD. You don’t have to use the Change authentication dialog to register and configure your application. It makes your life easier.
  • In the drop-down menus, select cloud – single Organization. Enter the domain for your Azure AD directory, for example abcyahoo.onmicosoft.com, and then click OK .

    Azure active directory
  • Then Run your application F5. Then for the first time it will ask you to change the password which you just created from the portal as default password.

  • Then set new password and here you will successfully have logged into your application with a new organization domain.

    Azure active directory

Summary

This is how you can authenticate your mvc application with Azure active directory.

Up Next
    Ebook Download
    View all
    Learn
    View all