How do I use forms authentication on specific directories?

Discussion in 'ASP .Net' started by Darrel, Apr 22, 2006.

  1. Darrel

    Darrel Guest

    My app has an 'admin' folder. This is the only directory i need to apply
    forms authentication to.

    Googling seems to indicate that the solution is to just give the admin
    folder it's own config file and set the authentication rules there.

    However, when I do that, I get this error:

    --------------------------
    Parser Error Message: It is an error to use a section registered as
    allowDefinition='MachineToApplication' beyond application level. This error
    can be caused by a virtual directory not being configured as an application
    in IIS.
    --------------------------------

    Which, from what I can tell, is saying I can't do forms authentication in a
    directory unless that directory is also an application.

    So, is there a way to do what I want to do? I want one subdirectory of my
    application (not an application itself) to use forms authentication.

    -Darrel
    Darrel, Apr 22, 2006
    #1
    1. Advertising

  2. Darrel

    Teemu Keiski Guest

    Hi,

    you need to declare the authentication method used on root web.config with
    <authenication> element, there's no way around that .

    But with <location> tags in root web.config or web.config files in
    subdirectories you can provide <authorization> elements to specify if
    accessing a folder (or specific aspx page) needs authentication. E.g in root
    web.config put
    <authorization>
    <allow users="*" />
    </authorization>

    But for specific subfolders you can deny it.

    <location path="subfolder">
    <system.web>
    <authorization>
    <deny users="?" />
    </authorization>
    </system.web>
    </location>

    (or place this into separate web.config file on subdirectiry when <location>
    wouldn't be needed)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    "Darrel" <> wrote in message
    news:...
    > My app has an 'admin' folder. This is the only directory i need to apply
    > forms authentication to.
    >
    > Googling seems to indicate that the solution is to just give the admin
    > folder it's own config file and set the authentication rules there.
    >
    > However, when I do that, I get this error:
    >
    > --------------------------
    > Parser Error Message: It is an error to use a section registered as
    > allowDefinition='MachineToApplication' beyond application level. This
    > error can be caused by a virtual directory not being configured as an
    > application in IIS.
    > --------------------------------
    >
    > Which, from what I can tell, is saying I can't do forms authentication in
    > a directory unless that directory is also an application.
    >
    > So, is there a way to do what I want to do? I want one subdirectory of my
    > application (not an application itself) to use forms authentication.
    >
    > -Darrel
    >
    Teemu Keiski, Apr 22, 2006
    #2
    1. Advertising

  3. Darrel

    Darrel Guest


    > <location path="subfolder">
    > <system.web>
    > <authorization>
    > <deny users="?" />
    > </authorization>
    > </system.web>
    > </location>
    >
    > (or place this into separate web.config file on subdirectiry when
    > <location> wouldn't be needed)


    Thanks, Teemu. That worked perfectly!

    -Darrel
    Darrel, Apr 22, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    2
    Views:
    1,451
    Tommy
    Feb 13, 2004
  2. =?Utf-8?B?TmF0aGFuVg==?=

    Forms Authentication across directories

    =?Utf-8?B?TmF0aGFuVg==?=, Oct 14, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    397
    =?Utf-8?B?U2FyYXZhbmE=?=
    Oct 14, 2004
  3. Jerry Morton
    Replies:
    1
    Views:
    567
    Mohamed El Ashmawy
    Oct 14, 2004
  4. tafs7
    Replies:
    0
    Views:
    120
    tafs7
    Apr 30, 2004
  5. Eric
    Replies:
    2
    Views:
    497
Loading...

Share This Page