ASP.NET – UserType-wise page access

Suppose I have 3 kinds of users and their accessible pages in my ASP.net application are as follows:

(1) User Type-A {Default.aspx, a.aspx, b.aspx and c.aspx},

(2) User Type-B {Default.aspx, d.aspx, e.aspx and f.aspx},

(4) Admin {Default.aspx and g.aspx}.

Here Default.aspx is my Login-page.

I am using Membership Provider and Forms authentication technique.

Now I need to block access of one type of user to the pages assigned for other type users.

How should I configure my Web.config file?

and What kind of c# code should be used?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Role management in asp.net may help you in this case. Please check this article.
You may have to customize this as per your specific requirement. Hope this helps.

Role Manager in ASP.NET

Each of User-Type will be associated with Roles.

Solution 2

We have a similar requirement, and make use of the Patterns and Practices Web Client Software Factory. Basically it assists you in creating modules, and allowing you to specify per-page access levels in config based on Role / User details.

Solution 3

You might have a try to use roleship provider and web.sitemap.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply