I can't open a web.config file in my ASP web project.
I can add config files in my project for set the authorization pages.
I need to open these pages to be able to update the "Roles" names from my admin page.
After following the sample from Microsoft, it should be working normally:
http://msdn.microsoft.com/en-us/library/vstudio/4c2kcht0(v=vs.100).aspx
Here is the C# code I use :
//Open the web.config custom
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/WebAuthorizationPilotageGeneral") as Configuration;
//Get the authorization section
// section is always == NULL !!!!
-> section = (System.Web.Configuration.AuthorizationSection)config.GetSection("authorization");
//Remove all Roles before add news Roles
section.Rules.Clear();
autho = new System.Web.Configuration.AuthorizationRule(System.Web.Configuration.AuthorizationRuleAction.Allow);
foreach (string role in Roles.GetAllRoles())
{
if (role != ttbx_RoleName.Text)
{
autho.Roles.Add(role);
}
}
//Add the news Roles
section.Rules.Add(autho);
//Save the web.config custom
config.Save(ConfigurationSaveMode.Full, true);
My web.config custom file I try to load to update "authorization" section
<!-- WebAuthorizationPilotageGeneral.config - access pilotage page -->
<authorization>
<allow roles="Administrator" />
<allow roles="Audit" />
<allow roles="Copil" />
<allow roles="System" />
<allow roles="User" />
<allow roles="visitor" />
<deny users="*" />
</authorization>
The weird things is after load the config file, my config object still have 22 sections, and should have only one => "authorization" , it's look like my (web.config) root file and not the (WebAuthorizationPilotageGeneral) config file.
UPDATE : I try to put my 4 config files on only one folder
Web.config file
In the MS examples, there is used relative config path without "~" symbol. Have you tried to remove it?
// Set the root path of the Web application that contains the
// Web.config file that you want to access.
string configPath = "/MyAppRoot";
// Get the configuration object to access the related Web.config file.
Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.