How to limit access to admin subfolder using web.config file?

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Re: How to limit access to admin subfolder using web.config file?

    For the 'admin' area, you should have something like the following i nthe
    authorisation section of your web.config:-

    <allow roles="AdminRole" />
    <deny users="*" />

    This way, only those users who have been assigned an admin role are allowed
    in, and everyone else is denied. For your login procedure, you need to do
    some form of user lookup (typically via DB) and assign an 'AdminRole' to the
    current user, and create a forms principle that is attached to the current
    HttpContext (HttpContext.Current.User) so that this role check can be
    performed by the runtime.

    --
    - Paul Glavich
    Microsoft MVP - ASP.NET


    "Frenny Thomas via .NET 247" <anonymous@dotnet247.com> wrote in message
    news:u6Koc2PjEHA.3664@TK2MSFTNGP12.phx.gbl...
    I'm in quite of a dilemma, and for the first time: all the articles and
    discussion forums on the 'net hasn't helped me get rid of my page errors :(

    I have my web.config file in the root directory. I have a subdirectory
    called /admin/ underneath it. I want all users to be able to view any page
    in the root directory. If a user tries to access any page in the /admin/
    subfolder, I want him/her to be redirected to a login page (located in the
    subfolder itself).

    I have tried two methods of doing the job, but neither have worked. Can
    anyone give me any suggestions/explanations??

    Method 1
    ----------------------------------------------------------------------------
    ----
    <configuration>
    <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
    <authorization>
    <allow users="*"/>
    </authorization>
    </system.web>


    <location path="admin">
    <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true"/>
    <authentication mode="Forms">
    <forms name="frmLogin"
    loginUrl="login.aspx">
    </forms>
    </authentication>
    <authorization>
    <deny users ="?" />
    </authorization>
    </system.web>

    </location>

    </configuration>

    Method 2 [After I moved the login.aspx page back up to the root directory]
    ----------------------------------------------------------------------------
    ----
    <configuration>
    <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" />
    <authentication mode="Forms">
    <forms name="frmLogin"
    path="/"
    loginUrl="login.aspx"
    protection="All"
    timeout="20"></forms>
    </authentication>
    <authorization>
    <allow users="*" />
    </authorization>
    </system.web>
    <location path="admin">
    <system.web>
    <authorization>
    <deny users="?" />
    </authorization>
    </system.web>
    </location>
    </configuration>

    -----------------------
    Posted by a user from .NET 247 ([url]http://www.dotnet247.com/[/url])

    <Id>Y8SOtJu2bEOu3CPsYMCl/w==</Id>


    Paul Glavich [MVP - ASP.NET] Guest

  2. Similar Questions and Discussions

    1. Location element in the Web.config file. Allow System Admin whole directory, allow others specific page
      Hello. I am developing an ASP.net C# application using forms authentication. I have a directory ManageUsers and I want all pages in that...
    2. how to limit authorization in admin subfolder from web.config
      I'm in quite of a dilemma, and for the first time: all the articles and discussion forums on the 'net hasn't helped me get rid of my page errors :(...
    3. web.config in subfolder
      Hi I am using remote web space and cannot seem to use my normal web.config file to secure the folder :-( <authentication mode="Forms"> <forms...
    4. file and printer sharing access limit
      the default limit of maximum simultaneous connections on sharing to a pc is 10 .... while we can change the maximum number of simultaneous access...
    5. Access to config file
      I'm writing C# ASP.NET application. For different parts of application I wrote different config files. When I was transferred files from my office...
  3. #2

    Default Re: How to limit access to admin subfolder using web.config file?

    Your second option was close, just need to add one more line to make it
    work.

    Here is the complete section
    <location path="admin">
    <system.web>
    <authorization>
    <deny users="?" />
    <allow users ="*" />
    </authorization>
    </system.web>
    </location>

    since you want to limit unauthenticated users from accessing the
    directory the deny users=? does that but once they are authenticated it
    does not specify who to let access the directory so you need the allow
    users="*" to accomplish that.

    Just curious though, why do you want all users to have access to your
    admin directory, you can limit this to just admins by specifying the
    administrator names or id, which ever you use in the allow users.

    Currently for one of my applications I have this set to
    <allow users="1"/> which only gives the administrator of my website
    access to the administration functions.

    thanks,
    Seth

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Seth Westfall Guest

  4. #3

    Default Re: How to limit access to admin subfolder using web.config file?

    change your second method to this:

    <configuration>
    <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" />
    <authentication mode="Forms">
    <forms name="frmLogin"
    path="/"
    loginUrl="login.aspx"
    protection="All"
    timeout="20"></forms>
    </authentication>
    <authorization>
    <allow users="*" />
    </authorization>
    </system.web>
    <location path="admin">
    <system.web>
    <authorization>
    <deny users="?" />
    <allow users="*" />
    </authorization>
    </system.web>
    </location>
    </configuration>

    adding the <allow users="*"/> after denying the unauthenticated.

    Since this is an admin directory you might not want to give access to
    all users but just specify specific logins:
    example:
    <allow users="administrator,bob,text,etc" />
    This will only give access to this directory to those users that are
    administrators of the application.

    Any other questions e-mail me at [email]tristealth@hotmail.com[/email]

    thanks,
    Seth


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Seth Westfall Guest

  5. #4

    Default Re: How to limit access to admin subfolder using web.config file?

    How do I 'assign a role' to a user? Once authenticated? Based on values
    I receive from the database query on that username and password?




    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Frenny Thomas Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139