As Alexey was implying in the post in the link that was included, parsing
the web.sitemap might be a way to do that. If you include the roles tag
for
you pages, you can determine the roles that are allowed for a giving
page.
It's a pain but it's a way to do it. You can use the HTTPConext to get at
the current user.
using System.Web.Configuration;
Configuration config =
WebConfigurationManager.OpenWebConfiguration(url);
AuthorizationSection configSection =
(AuthorizationSection)config.GetSection("system.web/authorization");
AuthorizationRuleCollection rules = configSection.Rules;
CommaDelimitedStringCollection allowed = new
CommaDelimitedStringCollection();
CommaDelimitedStringCollection denied = new
CommaDelimitedStringCollection();
for (int i = 0; i < rules.Count; i++)
{
if (rules
.Roles.Count > 0)
{
if (rules.Action.ToString() == "Allow")
allowed.AddRange(rules.Roles.ToString().Split(','));
else if (rules.Action.ToString() == "Deny")
denied.AddRange(rules.Roles.ToString().Split(','));
}
}
Response.Write("Allowed Roles: " + allowed.ToString());
Response.Write("<br />");
Response.Write("Denied Roles: " + denied.ToString());
Note, the url value can be a path to a directory, like "/admin", or a
path to the file, like "/admin/default.aspx". To find if roleName
"IsInRoles", simply use the Contains() method, e.g.
allowed.Contains("roleName").
Enjoy.