web.config中添加appSettings 的key如下<configuration>
<appSettings>
<add key="key1" value="abcd" />
</appSettings>
</configuration>
程序中如此访问key
ConfigurationSettings.AppSettings("key1")
<appSettings>
<add key="key1" value="abcd" />
</appSettings>
</configuration>
程序中如此访问key
ConfigurationSettings.AppSettings("key1")
web.config本身是程序运行时的配置文件,在设计时没有被读取,所以肯定读不出来了。你读它的目的呢?
那么在设计的时候能知道你所设计的页面的物理地址吗?
ConfigurationSettings.AppSettings["key1"]
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<appSettings>
<add key="MM_CONNECTION_STRING_aa" value="aaaaaaaaaaaa" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
读取:
Public str As String = System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_aa")
(string)System.Configuration.ConfigurationSettings.AppSettings["configName"]就可以取到值,
在你的*.csproj文件里中
<File
RelPath = "Web.config"
BuildAction = "Content"
/>配置了你的webconfig的路径
ITypeDescriptorContext context,
IServiceProvider provider,
object value ) { object serviceID = provider.GetService( typeof(ITypeResolutionService) );
ITypeResolutionService resolver = (ITypeResolutionService)provider.GetService( typeof(ITypeResolutionService) ); AssemblyName assemblyName = serviceID.GetType().Assembly.GetName(); string strPathName = resolver.GetPathOfAssembly( assemblyName );
//.......
}then load the web.config with classes in System.Xml
这样做是很有道理,但是为什么我按照你的方法做得到的strPathName是null?
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=Kh9YAeZXCHA.2428%40cpmsftngxa07
C:\Documents and Settings\Administrator\VSWebCache\WANG-WEI\Test\obj\Debug\Test.dll
这并不是我想要的是不是这一句
object serviceID = provider.GetService( typeof(ITypeResolutionService) );
写得有问题,请思归请教。
谢谢!
这个问题已经困扰我好多天了。
应该是c:\inetpub\wwwroot\Test\。