Link to home
Start Free TrialLog in
Avatar of VBBRett
VBBRett

asked on

How do you specify access to admins in web applications?

How do you specify who has access in asp.net applications?  Is it in the web.Config file?  If so, please give me step by step instructions on how to do this.  Thanks!
ASKER CERTIFIED SOLUTION
Avatar of TimSledge
TimSledge
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you're going to use FormsAuthentication (which is probably the easiest)  then you can set up Roles from the Website Administration Tool in VS (Website > ASP.NET Configuration). Then you can assign users to be part of a certain Role. You can then check in your code which Role the currently logged on user is in.

You can also set up folders in your application for specific roles. So that you can seperate pages that are only meant to be viewed by users in a certain role. You then create a web.config in each of these folders which specifies which user roles are allowed access to the pages in the given folder.

Eg. You can create a folder in your project called Admin, and put all the pages that only the Administrators will use, in this folder. Then add a web.config file to that folder, which would contain the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authorization>
            <allow roles="Administrator" />
        </authorization>
    </system.web>
</configuration>

Assuming of course that your admin role is called "Administrator".

Here is a Microsoft tutorial, which shows you step by step -> http://www.asp.net/Learn/Security/tutorial-02-vb.aspx
Avatar of VBBRett
VBBRett

ASKER

So when you setup folders specific roles, do you put the admin pages in the admin folder and the regular user pages in the regular user folder?  How do you set it up so the admin has access to everything?  This is interesting to me and this seems a but complex.  Please let me know.  Thanks!
Yes, but for each role you can set up folders. If you want to allow admins to access the other folders too then your config file for the user's folder would look something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authorization>
            <allow roles="User" />
            <allow roles="Administrator" />
        </authorization>
    </system.web>
</configuration>

so that will allow the users and admins to access the contents of that folder..