views:

231

answers:

1

Hi Guys,

I'd like to use the built in directory security features built into the web.config to restrict access to child pages of a parent page. My structure is as follows:

  • Members
  • Members/News
  • Members/Press
  • Members/Movies

Users should be able to have access to the members parent page, but not child pages. My problem is, because I am using extensionless URLs, the web.config thinks this is a directory and so access is blocked. Is there a way to say only restrict access for sub pages?

+1  A: 

This configuration should do the trick. It is enabling anonymous access for the entire website, except for the additional locations - they need an authenticated user to work.

<configuration>
    <system.web>
        <authentication mode="Forms">
            <forms loginUrl="Login" defaultUrl="Members" />
        </authentication>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>

    <location path="Members/News">
        <system.web>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

    <location path="Members/Press">
        <system.web>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

    <location path="Members/Movies">
        <system.web>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

</configuration>
Fábio Batista
Hi. Whilst this works, I would like to be able to do it somehow by only defining it at the "Members" level (like how it works if you had a .aspx extension) as the sub pages are managed via CMS, so I can't quarantee what the sub pages would be.
Matt Brailsford
I don't know if the <location> element support wildcards (have you tried <location path="Members/*"> to see how it behaves?).If you need a wildcard authorization, maybe you can write your own HttpModule to take care of the authorization for you.Take a look at this guy's implementation of his own basic CustomUrlAuthorizationModule: http://forums.asp.net/t/1346678.aspx
Fábio Batista
The location attribute doesn't support wildcards as this was one of the first things I tried. The CustomUrlAuthorizationModule might be a goer though. I'll look into it further. Thanks for you help.
Matt Brailsford