Forms auth / Location element

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

  1. #1

    Default Forms auth / Location element

    Greetings!

    I am attempting to secure the root of an IIS virtual directory and an Admin subdirectory separately from one another. At first, I attempted to create an additional Web.Config in the /Admin folder to direct unauthenticated access attempts to URLs within this directory to a different login page. The ASP.Net runtime complained that the <authentication/> element should only be used at the root level (or perhaps it was the <forms/> element).

    After returning to the drawing board, I attempted to create two <location/> elements within the root level Web.Config file. The contents of the root Web.Config file are inserted below. There are two <location/> elements. One for the root of the virtual directory and another for the /Admin subdirectory.

    Unauthenticated attempts to access root level URLs are properly redirected to /Login.aspx. However, once authenticated to this folder the client may request any URL within the /Admin folder without being subject to the additional authentication/authorization that I would like to enforce upon administrative use.

    Is it the case that "Forms" based authentication can only be employed once during a client's session? (i.e. Once they are authenticated, they are authenticated ... period!) And also, that only one form can be established for a particular IIS virtual directory or application? If this is not the case, then any guidance as to what I have configured wrong will be greatly appreciated.


    Thanks in advance,
    Mark

    Contents of Web.Config follow:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>

    <location>
    <system.web>
    <compilation defaultLanguage="vb" debug="true" />

    <customErrors mode="Off" />

    <authentication mode="Forms">
    <forms name=".rootAccessCookie" loginUrl="Login.aspx" protection="All" timeout="30" path="/" />
    </authentication>

    <authorization>
    <deny users="?" /> <!-- Deny all unauthenticated/unauthorized users -->

    </authorization>

    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />

    <sessionState
    mode="InProc"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="20"
    />

    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />

    </system.web>
    </location>

    <location path="Admin/">
    <system.web>

    <compilation defaultLanguage="vb" debug="true" />

    <customErrors mode="Off" />

    <authentication mode="Forms">
    <forms name=".adminAccessCookie" loginUrl="Admin/Login.aspx" protection="All" timeout="30" path="Admin/" />
    </authentication>

    <authorization>
    <deny users="?" /> <!-- Deny all unauthenticated/unauthorized users -->

    </authorization>

    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />

    <sessionState
    mode="InProc"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="20"
    />

    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />

    </system.web>
    </location>

    </configuration>


    Mark Teague Guest

  2. Similar Questions and Discussions

    1. Forms Auth Info passed to Windows Auth?
      The requirement is to build an ASP.Net intranet application, so external users can log in to the main web portal via forms authentication, using...
    2. FORMS AUTH HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      I'm using forms Auth! Why am i getting the error:-I HAVE DONE EVRYTHING NEEDED! Error authenticating. Error obtaining group names. The specified...
    3. Help with forms auth
      Hi, I am using forms Auth on my WEB APP. I am checking the credentials in sql server. When a user request any page other than login.aspx they get...
    4. Configuring Windows Auth & Forms Auth in Asp.Net
      Configuring Windows Auth & Forms Auth in Asp.Ne Hi, I've configured a web app to use windows authentication and also set up two separate...
    5. impersonation and location element
      I have an asp.net app with one sub folder that requires windows authentication. The IIS folder is set to require intergrated security and the sub...
  3. #2

    Default Re: Forms auth / Location element

    Hello Mark,

    you so far only used deny="?" -

    there are also <allow user=".." /> and <allow role=".." />

    to give different users different access rights to your application, you
    have to couple the users with roles, a common place to do this is in the
    AuthenticateRequest event in gobal.asax or a HttpModule...

    your web.config could look like this then:

    <location path="Admin/">
    <system.web>
    <authorization>
    <allow roles="Admin" />
    <deny users="*" />
    </authorization>
    </system.web>
    </location>

    for an example how to do it - you can download this sample:
    [url]http://www.leastprivilege.com/content/binary/FormsAuthBestPractice.zip[/url]


    ---------------------------------------
    Dominick Baier - DevelopMentor
    [url]http://www.leastprivilege.com[/url]
    > Greetings!
    >
    > I am attempting to secure the root of an IIS virtual directory and an
    > Admin subdirectory separately from one another. At first, I attempted
    > to create an additional Web.Config in the /Admin folder to direct
    > unauthenticated access attempts to URLs within this directory to a
    > different login page. The ASP.Net runtime complained that the
    > <authentication/> element should only be used at the root level (or
    > perhaps it was the <forms/> element).
    >
    > After returning to the drawing board, I attempted to create two
    > <location/> elements within the root level Web.Config file. The
    > contents of the root Web.Config file are inserted below. There are
    > two <location/> elements. One for the root of the virtual directory
    > and another for the /Admin subdirectory.
    >
    > Unauthenticated attempts to access root level URLs are properly
    > redirected to /Login.aspx. However, once authenticated to this folder
    > the client may request any URL within the /Admin folder without being
    > subject to the additional authentication/authorization that I would
    > like to enforce upon administrative use.
    >
    > Is it the case that "Forms" based authentication can only be employed
    > once during a client's session? (i.e. Once they are authenticated,
    > they are authenticated ... period!) And also, that only one form can
    > be established for a particular IIS virtual directory or application?
    > If this is not the case, then any guidance as to what I have
    > configured wrong will be greatly appreciated.
    >
    > Thanks in advance,
    > Mark
    > Contents of Web.Config follow:
    > <?xml version="1.0" encoding="utf-8" ?>
    > <configuration>
    > <location>
    > <system.web>
    > <compilation defaultLanguage="vb" debug="true" />
    > <customErrors mode="Off" />
    >
    > <authentication mode="Forms">
    > <forms name=".rootAccessCookie" loginUrl="Login.aspx"
    > protection="All" timeout="30" path="/" />
    > </authentication>
    > <authorization>
    > <deny users="?" /> <!-- Deny all unauthenticated/unauthorized
    > users -->
    > </authorization>
    >
    > <trace enabled="false" requestLimit="10" pageOutput="false"
    > traceMode="SortByTime" localOnly="true" />
    >
    > <sessionState
    > mode="InProc"
    > stateConnectionString="tcpip=127.0.0.1:42424"
    > sqlConnectionString="data
    > source=127.0.0.1;Trusted Connection=yes"
    > cookieless="false"
    > timeout="20"
    > />
    > <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    >
    > </system.web>
    > </location>
    > <location path="Admin/">
    > <system.web>
    > <compilation defaultLanguage="vb" debug="true" />
    >
    > <customErrors mode="Off" />
    >
    > <authentication mode="Forms">
    > <forms name=".adminAccessCookie" loginUrl="Admin/Login.aspx"
    > protection="All" timeout="30" path="Admin/" />
    > </authentication>
    > <authorization>
    > <deny users="?" /> <!-- Deny all unauthenticated/unauthorized
    > users -->
    > </authorization>
    >
    > <trace enabled="false" requestLimit="10" pageOutput="false"
    > traceMode="SortByTime" localOnly="true" />
    >
    > <sessionState
    > mode="InProc"
    > stateConnectionString="tcpip=127.0.0.1:42424"
    > sqlConnectionString="data
    > source=127.0.0.1;Trusted Connection=yes"
    > cookieless="false"
    > timeout="20"
    > />
    > <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    >
    > </system.web>
    > </location>
    > </configuration>
    >


    Dominick Baier [DevelopMentor] 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