views:

64

answers:

2

Hi

I need to restric access to my admin folder to certain people. Those with no authentication ticket should be redirectered to a "not allowed page". How do I identify all pages in my admin folder. I have so far but is it OK?

If url.Contains("/admin") Then

'If authentication ticket incorrect then

        `Response.Redirect("~/notallowed_admin.aspx")`

End If

And not, I cannot use my web.config for this particular issue.

Many thanks

A: 

If url.contains("/admin") should be sufficient in most cases. Most programmers would find it to be a bit if a KLUDGE, though.

You could also write an abstract class to inherit from the Page class which contains the code to check the authorization and then redirect. Then, you could declare the classes for all the code-behind files in the admin folder to inherit the class.

I believe that yes, what you want to do is possible, though anything you do will be a bit of a KLUDGE form a .net point of view because web.config is what MS provides to specify how to do authorization.

Rice Flour Cookies
Thanks very much. I'm alreading using web.config to restrict access to the whole site, but the admin section can only be accessed by people with "admin accounts". These people's usernames are stored in a database that I call when a user comes to the site. If there is an admin account for them then the admin section is available, otherwise they can only see the rest of the site.
netNewbi3
If you're using AD accounts, you may be able to set restrictions using the directory security.
Rice Flour Cookies
I've used this approach many times on other sites and I prefer it as it is a bit more clear to me what page is actually restricted.
Paul Mendoza
+1  A: 

You should put the security check to Global.asax

Also, it would be wise to replace you condition with more precise match by regexp to avoid occasional mismatches.

    protected override void Application_BeginRequest(Object sender, EventArgs e) {
        if (Regex.IsMatch(Request.Url.ToString(),@".*/system\.aspx/admin.*\.aspx",RegexOptions.IgnoreCase)) {
            Response.Redirect("~/AdminSecurityCheck.aspx");
            return;
        }
        .......
    }
buru