IConfigurationSectionHandler的问题

我按照Duwamish7的DuwamishConfiguration和ApplicationConfiguration自己写了个一样的配置类,怎么不读不出配置文件(web.config)里面的东西啊,web.config和我自己写的那个类是照着Duwamish7写的继承了IConfigurationSectionHandler接口

类如下:

None.gif public   class  MCConfiguration : IConfigurationSectionHandler
ExpandedBlockStart.gifContractedBlock.gif 
dot.gif {
InBlock.gif  
InBlock.gif  
private const string DATAACCESS_CONNECTIONSTRING = "ChintMC.DataAccess.ConnectionString";
InBlock.gif  
private const string DATAACCESS_OLEDBDATASOURCE  = "ChintMC.DataAccess.OleDbdataSource";
InBlock.gif  
InBlock.gif  
private static String dbConnectionString;
InBlock.gif  
private static String dbOleDbdataSource;
InBlock.gif  
InBlock.gif  
private const String DATAACCESS_CONNECTIONSTRING_DEFAULT = "server=LM;User ID=sa;Password=;database=MC_DB;Connection Reset=FALSE";
InBlock.gif  
private const String DATAACCESS_OLEDBDATASOURCE_DEFAULT  = "Provider=SQLOLEDB ;Server=192.168.207.181;Address=192.168.207.181,1433;Database=MC_DB;Uid=sa;Pwd=;";
InBlock.gif  
InBlock.gif  
public Object Create(Object parent, object configContext, XmlNode section)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   NameValueCollection settings;
InBlock.gif            
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    NameValueSectionHandler baseHandler 
= new NameValueSectionHandler();
InBlock.gif    settings 
= (NameValueCollection)baseHandler.Create(parent, configContext, section);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    settings 
= null;
ExpandedSubBlockEnd.gif   }

InBlock.gif            
InBlock.gif   
if ( settings == null )
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    dbConnectionString 
= DATAACCESS_CONNECTIONSTRING_DEFAULT;
InBlock.gif    dbOleDbdataSource 
= DATAACCESS_OLEDBDATASOURCE_DEFAULT;
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    dbConnectionString 
= ReadSetting(settings, DATAACCESS_CONNECTIONSTRING, DATAACCESS_CONNECTIONSTRING_DEFAULT);
InBlock.gif    dbOleDbdataSource 
= ReadSetting(settings, DATAACCESS_OLEDBDATASOURCE, DATAACCESS_OLEDBDATASOURCE_DEFAULT);
ExpandedSubBlockEnd.gif   }

InBlock.gif            
InBlock.gif   
return settings;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif 
InBlock.gif  
public static String ConnectionString
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return dbConnectionString;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
InBlock.gif  
public static String OleDbdataSource
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return dbOleDbdataSource;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif    
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif  
ReadingSettings#region ReadingSettings
InBlock.gif 
InBlock.gif  
public static String ReadSetting(NameValueCollection settings, String key, String defaultValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Object setting 
= settings[key];
InBlock.gif                
InBlock.gif    
return (setting == null? defaultValue : (String)setting;
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return defaultValue;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif        
InBlock.gif  
InBlock.gif  
public static bool ReadSetting(NameValueCollection settings, String key, bool defaultValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Object setting 
= settings[key];
InBlock.gif                
InBlock.gif    
return (setting == null? defaultValue : Convert.ToBoolean((String)setting);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return defaultValue;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif        
InBlock.gif  
InBlock.gif  
public static int ReadSetting(NameValueCollection settings, String key, int defaultValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Object setting 
= settings[key];
InBlock.gif                
InBlock.gif    
return (setting == null? defaultValue : Convert.ToInt32((String)setting);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return defaultValue;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif        
InBlock.gif  
public static TraceLevel ReadSetting(NameValueCollection settings, String key, TraceLevel defaultValue)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
try
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Object setting 
= settings[key];
InBlock.gif                
InBlock.gif    
return (setting == null? defaultValue : (TraceLevel)Convert.ToInt32((String)setting);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return defaultValue;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif        
ExpandedSubBlockEnd.gif  
#endregion

InBlock.gif
web.config如下:
None.gif <? xml version="1.0" encoding="utf-8"  ?>
None.gif
< configuration >
None.gif  
< configSections >
None.gif 
< section  name ="MCConfiguration"  type ="ChintMC.Common.MCConfiguration, ChintMC.Common"   />
None.gif  
</ configSections >
None.gif  
< system .web >
None.gif    
< compilation 
None.gif         
defaultLanguage ="c#"
None.gif         debug
="true"
None.gif    
/>
None.gif    
< customErrors 
None.gif    
mode ="RemoteOnly"  
None.gif    
/>  
None.gif    
None.gif    
< authentication  mode ="Forms"   />  
None.gif    
None.gif    
< trace
None.gif        
enabled ="false"
None.gif        requestLimit
="10"
None.gif        pageOutput
="false"
None.gif        traceMode
="SortByTime"
None.gif  localOnly
="true"
None.gif    
/>
None.gif
None.gif    
< sessionState 
None.gif            
mode ="InProc"
None.gif            stateConnectionString
="tcpip=127.0.0.1:42424"
None.gif            sqlConnectionString
="data source=127.0.0.1;user id=sa;password="
None.gif            cookieless
="false"  
None.gif            timeout
="20"  
None.gif    
/>
None.gif
None.gif    
< globalization 
None.gif            
requestEncoding ="utf-8"  
None.gif            responseEncoding
="utf-8"  
None.gif   
/>
None.gif   
None.gif 
</ system.web >
None.gif 
< MCConfiguration >
None.gif 
< add  key ="ChintMC.DataAccess.OleDbdataSource"  value ="Provider=SQLOLEDB ;Server=192.168.207.181;Address=192.168.207.181,1433;Database=MC_DB;Uid=sa;Pwd=;"   />
None.gif 
< add  key ="ChintMC.DataAccess.ConnectionString"  value ="server=LM;User ID=sa;Password=;database=MC_DB;Connection Reset=FALSE"   />
None.gif 
</ MCConfiguration >
None.gif
None.gif
</ configuration >

麻烦指点一下吧,报的错是 字符串没有实例化
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值