【发布时间】:2014-07-16 13:29:26
【问题描述】:
我无法在我的 ASP Web 项目中打开 web.config 文件。
我可以在我的项目中添加配置文件来设置授权页面。
我需要打开这些页面才能从我的管理页面更新“角色”名称。
按照微软的示例后,它应该可以正常工作:
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) 配置文件。
更新:我尝试将我的 4 个配置文件放在一个文件夹中
Web.config 文件
【问题讨论】:
标签: c# asp.net web-config