C# Asp.net Azure Authorization Certain Pages

Ronald Lawrimore 1 Reputation point
2021-04-01T13:34:41.563+00:00

I am working on a simple website that will use Azure for authentication and authorization. I have 5 actual aspx pages. I need to have certain pages restricted so that based on who is logged into the site with there credentials they do or don't have access. I would like to use app roles from Azure to control this but need some help. I am not sure what to do to get this going and can only find examples of asp. core.

i have already created my roles on the app in Azure.
Admin
Non-Admin

Any help would be appreciated.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,312 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,379 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 49,246 Reputation points
    2021-04-01T14:40:52.473+00:00

    You didn't specify what version of ASP.NET you are using. For ASP.NET MVC (not Core) it is documented here. In general you will globally configure authentication. For controllers (or actions) that require different rules you'll use the Authorize attribute on the controller/action to specify the role(s) you need for that specific action/controller. If anyone needs access then you'll use AllowAnonymous instead. If your site mostly is for unauthenticated users then you would simply apply the Authorize attribute to the controllers/actions that need it. In general it is recommended that you isolate your controllers such those needing security are separate from those that don't.

    For ASP.NET Core it is a similar process but APIs and MVC controllers are combined into one. Here's the article on implementing role-based in ASP.NET Core.

    If you are using WebForms then the process is different. Security is configured in the web.config using the location elements.