I have a small problem trying to modify my Web.config from code. All I'm trying to do is access my authorization rules and add a bunch, which will be later useful for any administrator of the page. However, I have no idea how to get past - the piece of code that keeps everything together, restricting access to the folder.
Here is the Web.config part:
<location path="Admin" >
<system.web >
<authorization>
<allow roles="Administrator, Superadministrator" />
<deny users="*"/>
</authorization>
</system.web>
And here is the code:
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (AuthorizationSection)configuration.GetSection("system.web/authorization");
var info3 = section.Rules[0].Roles.ToString();
section.Rules[0].Roles.Add("Ultraadministrator");
var info33 = section.Rules[0].Roles.ToString();
Label1.Text = info33;
configuration.Save();
The problem is in the GetSection part, I'd like to the location, but I have no idea how to. Can anyone help?