Results 1 to 9 of 9

Thread: [RESOLVED] Combining web.config role authorization with web.sitemap?

  1. #1
    Frenzied Member tr333's Avatar
    Join Date
    Nov 04
    Location
    /dev/st0
    Posts
    1,426

    Resolved [RESOLVED] Combining web.config role authorization with web.sitemap?

    I have a sitemap defined in a web.sitemap file and I'm also doing role-based authorization for locations using web.config. I'm using the web.sitemap to generate a menu structure on a Master page, and I wanted to somehow hook the role-based auth from web.config into my menu to hide links to pages that would be denied access from the roles auth.

    Is it possible to read the list of <location path=""> and associated role authorizations (allow or deny) from web.config so I can check that against the web.sitemap when generating the menu structure?
    Don't forget about rep points if you think a post has benefited you in any way.
    Just another Perl hacker,

  2. #2
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,513

    Re: Combining web.config role authorization with web.sitemap?

    Well this seems like a lot because you have to dig through the elements of web.config and find the correct ones.I haven't tried advanced digging on web.config but if you feel up to then have a look here and expand the example:
    http://www.dotnetcurry.com/ShowArticle.aspx?ID=102
    Slow as hell.

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 04
    Location
    /dev/st0
    Posts
    1,426

    Re: Combining web.config role authorization with web.sitemap?

    Thanks. I'll take a look and see how I go with it.
    Don't forget about rep points if you think a post has benefited you in any way.
    Just another Perl hacker,

  4. #4
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,513

    Re: Combining web.config role authorization with web.sitemap?

    No problem, let us know if you have any trouble.
    Slow as hell.

  5. #5
    Frenzied Member tr333's Avatar
    Join Date
    Nov 04
    Location
    /dev/st0
    Posts
    1,426

    Re: Combining web.config role authorization with web.sitemap?

    It's possible to do this manually:

    C# Code:
    1. var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/WebsiteVirtualRootThatContainsWebConfigGoesHere");
    2. var locations = config.Locations;
    3.  
    4.             foreach (ConfigurationLocation location in locations)
    5.             {
    6.                 AuthorizationSection authSection = (AuthorizationSection)location.OpenConfiguration().GetSection("system.web/authorization");
    7.                 foreach (AuthorizationRule authRule in authSection.Rules)
    8.                 {
    9.                     switch (authRule.Action)
    10.                     {
    11.                         case AuthorizationRuleAction.Allow:
    12.                             break;
    13.                         case AuthorizationRuleAction.Deny:
    14.                             break;
    15.                     }
    16.                 }
    17.             }

    But it's much easier to just set securityTrimmingEnabled="true" for the Sitemap provider in web.config, and this will automatically trim down the Sitemap nodes when accessing from code to whatever the current user is authorized to view. If you want to check a url manually, then you can just use UrlAuthorizationModule.CheckUrlAccessForPrincipal.
    Don't forget about rep points if you think a post has benefited you in any way.
    Just another Perl hacker,

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,733

    Re: [RESOLVED] Combining web.config role authorization with web.sitemap?

    Hey,

    Did you see my CodeBank Entry on this topic:

    http://www.vbforums.com/showthread.p...75#post3625975



    Gary

  7. #7
    Frenzied Member tr333's Avatar
    Join Date
    Nov 04
    Location
    /dev/st0
    Posts
    1,426

    Re: [RESOLVED] Combining web.config role authorization with web.sitemap?

    I must have missed that one. I'll take a look. Thanks.
    Don't forget about rep points if you think a post has benefited you in any way.
    Just another Perl hacker,

  8. #8
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,733

    Re: [RESOLVED] Combining web.config role authorization with web.sitemap?

    Quote Originally Posted by tr333 View Post
    I must have missed that one. I'll take a look. Thanks.
    Not a problem at all, hope it helps!

    Gary

  9. #9
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,733

    Re: [RESOLVED] Combining web.config role authorization with web.sitemap?

    Quote Originally Posted by tr333 View Post
    I must have missed that one. I'll take a look. Thanks.
    Not a problem at all, hope it helps!

    Gary

Posting Permissions

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