如何读取MaxRequestLength的值----(.net2.0)


在.net2.0中新增类HttpRuntimeSection :

  static   public   double  getMaxlength()
    
{
        System.Web.Configuration.HttpRuntimeSection hrs 
=   new  System.Web.Configuration.HttpRuntimeSection();
       
/// /return hrs.MaxRequestLength * 1024;
         return  hrs.MaxRequestLength ;
    }
 


但上述方法读到的值却始终是4096,查阅MSDN,得知System.Web.Configuration(.net2.0中新增的类)的属性和方法除了AppSettings之外均只能读取"不可自定义的属性和功能 ",没有更好的办法,只好折衷:用.net1.1的方法解决:

  static   public   string  getMaxlengthByAppSetting()
    
{
        
// 先在Web.Config文件中增加一个key **************************************** //
        
//   <appSettings>
        
//   <add key="maxRequestLength" value="1550000"/>
        
// </appSettings>
        
// 再来读取这个值,遗憾的是,这样只能写两遍,即
        
// <system.web>
        
// <httpRuntime maxRequestLength="1550000"  executionTimeout="3600"/>
        
// </system.web>
        
// 这两个值必须保持一致。
        Configuration config  =  WebConfigurationManager.OpenWebConfiguration( " ~ " );
        
return  config.AppSettings.Settings[ " maxRequestLength " ].Value;

       
/*  *********************以下为修改某个AppSettings的Key值。
        ////Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
        ////if (config.AppSettings.Settings["MyAppKey"] == null)
        ////    config.AppSettings.Settings.Add("MyAppKey", "Hello!");
        ////else
        ////    config.AppSettings.Settings["MyAppKey"].Value = "Hello2!";
        ////config.Save(); 
        
*/

       
    }



不知有没有更好的办法??

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值