Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  


Determine which roles can access a .NET page
If your site has several web.config files specifying security by role to various pages, you may want to know for any given page, who has access?

One way to easily accomplish this is to loop over a list of your known roles, and for each, use the UrlAuthorizationModule class (System.Web.Security) to determine if the role has access to the page in question:

List allowedRoles = new List ();
foreach (string roleName in GetAllRoleNames())
if (UrlAuthorizationModule.CheckUrlAccessForPrincipal(
Request.Path, new GenericPrincipal(new GenericIdentity(""), new string[] { roleName }), Request.RequestType))

This is working in .NET 4.0.

Created By: amos 3/15/2013 3:33:27 PM
Updated: 3/15/2013 3:35:07 PM