Home > .NET, asp.net, C#, Tips > Read Authorization section from Web.config

Read Authorization section from Web.config

In my current project, I had to read the find the Windows group for the ESB portal which can be found in the authorization section of the web.config for the ESB portal. I used the following code to read it:

var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(“/Bam”, “Default web Site”);
var section = config.GetSection(“system.web/authorization”) as AuthorizationSection;

if (section == null)
    return string.Empty;

foreach (AuthorizationRule rule in section.Rules)
     if (rule.Action.ToString().ToLower() == “allow” && rule.Roles.Count > 0)
        foreach (var item in rule.Roles)
            if (item != “*”)
                return rule.Roles[0];
return string.Empty;


Categories: .NET, asp.net, C#, Tips Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: