VS.NET2005通过SystemWebSectionGroup访问web.config中system.web下面的内容

Asp.Net2.0中我们可以方便的访问配置文件中,.NetFrameWork2.0新增加了 SystemWebSectionGroup 类。
允许用户以编程方式访问配置文件的 system.web 组。
比如判断web.config内是否为 debug="true",或者判断身份验证形式

 

      //get the web application configuration

//WebConfigurationManager.OpenWebConfiguration配置文件的虚拟目录,如果null则取根目录下的web.config
        System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("");


        //get the <system.web> group
        SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web");
       
        
        // Get the compilation section.
        CompilationSection compilation =
            systemWeb.Compilation;
        // Read section information.
        SectionInformation        info =compilation.SectionInformation;
       string name = info.SectionName;
        string type = info.Type;
        string declared = info.IsDeclared.ToString();
        string msg = String.Format("Name:     {0}/nDeclared: {1}/nType:     {2}/n",    name, declared, type);

        Response.Write(msg);
        AuthenticationSection auth = systemWeb.Authentication;
        SectionInformation info = auth.SectionInformation;
        string name = info.SectionName;
        string type = info.Type;
        string declared = info.IsDeclared.ToString();
        Response.Write("name:"+name+"/n"+"Declared:"+declared+"/n"+"Type:"+type);
Response.Write(systemWeb.Debug);//获取Debug属性值

本示例只获取Authentication的配置内容,要获取其它的配置内容可以参见MSDN文档。

 
附:SystemWebSectionGroup 类的公共属性: <script type="text/Javascript"> var ExpCollDivStr=ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl066893b77,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl06img,"; </script> (MSDN)

  名称 说明
Public property AnonymousIdentification 获取 anonymousIdentification 节。
Public property Authentication 获取 authentication 节。
Public property Authorization 获取 authorization 节。
Public property BrowserCaps
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值