WebConfigurationManager如何在目录中动态添加web.config并添加相应的节?
htjuw 2011-06-21 05:21:40 由于项目需要动态生成目录,想通过web.config控制目录中文件的访问权限,需要在建立目录的时候动态生成web.config并写入以下内容:
<?xml version="1.0"?>
<configuration>
<location path="123.rar">
<system.web>
<authorization>
<allow roles="Administrators,proBudgetInputer" />
<deny users="*" />
</authorization>
</system.web>
</location>
<system.web>
<authorization>
<allow roles="Administrators,baseBudgetInputer,proBudgetInputer" />
<deny users="*" />
</authorization>
</system.web>
</configuration>
cs文件
using System.Configuration;
using System.Web.Configuration;
写了以下两行代码就不知道怎么弄了
System.Configuration.Configuration cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(@"/test");
System.Web.Configuration.AuthorizationSection sec = new AuthorizationSection();