Search code examples
webformsazure-active-directoryazure-ad-msal

Implementing Azure AD authentication in web form application


I have an web application created on web form .net 4 (classic). It uses the asp.net membership and session for user authentication.

Now we want to take this app to azure and want to use the Azure AD authentication. I read the below document and found that it can be achieved and went through the steps. But I do have a question. https://devblogs.microsoft.com/premier-developer/convert-asp-net-webforms-with-windows-authentication-to-use-aad/

If the application is enabled to use Azure AD Authentication to login and logout. How the aspx page would be verified for authorization.

In MVC we can add the [Authorize] attribute on the controller level or on the action. How I can translate into aspx page.


Solution

  • Please check if you can use roles to direct to the aspx page. something like :

    if(User.IsUserInRole("Admin"))
    {
        //do something
    }  
    

    or try Configure web config like this.

    <location path="Account/<pagename>.aspx">
    <system.web>
        <authorization>
            <allow roles="Admin"/>
            <deny users="*" />
        </authorization>
    </system.web>
    
    </location>
    

    Reference