我无法在ASP Web项目中打开web.config文件。
我可以在项目中添加配置文件以设置授权页面。
我需要打开这些页面才能从我的管理页面更新“角色”名称。
在遵循Microsoft的示例之后,它应该可以正常工作:
http://msdn.microsoft.com/en-us/library/vstudio/4c2kcht0(v=vs.100).aspx
这里是我使用的C#代码:
//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);
我尝试加载以更新“授权”部分的我的web.config自定义文件
<!-- 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>
奇怪的是在加载配置文件后,我的配置对象仍然有22个部分,并且应该只有一个=>“ authorization”,它看起来像我的(web.config)根文件,而不是(WebAuthorizationPilotageGeneral)配置文件。
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9abnFrei5wbmcifQ==” alt =“在此处输入图像说明”>“ >>
更新:我尝试将4个配置文件放在一个文件夹中
Web.config文件
我无法在ASP Web项目中打开web.config文件。我可以在项目中添加配置文件以设置授权页面。我需要打开这些页面才能从我的...
在MS示例中,使用的相对配置路径不带“〜”符号。您是否尝试将其删除?