How to set Roles and access to certain pages

In ASP.NET forum very often a question is asked. How to set Roles and accordingly restrict access to certain pages?

There are definitely various ways. But I prefer UserControl. Its advantage is you can drag it to the Masterpage and its functionality has been used all along your application.

Here the main problem is I can’t use the code so I upload codes as Images part by part.

Here is the code:

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

set Roles and access to certain pages

Here I used few controls like LoginView, LogInStatus and lastly in the Page_Load event handler I checked whether User.Identity.IsAuthenticated. It can be used as User.IsInRole also to check the user belongs to a certain Role or not.

In this way, one can check whether a user belongs to the Role Administrator or Member, if he/she is Administrator can go to CatalogAdmin.aspx and if he/she belongs to the Role of  Member, then he/she might have access to Member_1.aspx page.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s