我按照书的测试一下如何读取config.web中的内容,但出错。
config.web中的内容
++++++++++++++++++++++++++++++
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<configsections>
<add name="test" type="System.Web.Configuration.DictionarySectionHandler" />
</configsections>
<test>
<add key="key" value="just a configure test" />
</test>
</configuration>
+++++++++++++++++++++++++++
读取页面的内容
+++++++++++++++++++++++++
<%@ Page Language="vb" Debug="true" %>
<script runat="server">
sub page_load(s as object ,e as eventargs)
Dim CfgSection As Hashtable = Context.GetConfig("test")
Dim Msg As String = cstr(CfgSection("key"))
response.write(Msg )
end sub
</script>
++++++++++++++++++++++++
提示错误: System.NullReferenceException: 未将对象引用设置到对象的实例。
指向:Dim Msg As String = cstr(CfgSection("key"))
求教了!!
config.web中的内容
++++++++++++++++++++++++++++++
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<configsections>
<add name="test" type="System.Web.Configuration.DictionarySectionHandler" />
</configsections>
<test>
<add key="key" value="just a configure test" />
</test>
</configuration>
+++++++++++++++++++++++++++
读取页面的内容
+++++++++++++++++++++++++
<%@ Page Language="vb" Debug="true" %>
<script runat="server">
sub page_load(s as object ,e as eventargs)
Dim CfgSection As Hashtable = Context.GetConfig("test")
Dim Msg As String = cstr(CfgSection("key"))
response.write(Msg )
end sub
</script>
++++++++++++++++++++++++
提示错误: System.NullReferenceException: 未将对象引用设置到对象的实例。
指向:Dim Msg As String = cstr(CfgSection("key"))
求教了!!
++++++++++++++++++++++++++++++
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<appSettings>
<add key="ConnectionString1" value="Provider=sqloledb;Data source=10.2.10.10;initial catalog=northwind;password=as;user id=sa;"/>
<add key="ConnectionString2" value="Provider=sqloledb;Data source=10.2.11.10;initial catalog=master;password=as;user id=sa;"/>
</appSettings>
</configuration>
++++++++++++++++++++++++++++++++++++dim a as string = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString1")
dim b as string = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString2")
++++++++++++++++++++++
<%@ Page Language="vb" Debug="true" %>haha<script runat="server">
sub page_load(sender as object ,e as eventargs)
dim a as string = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString1")
dim b as string = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString2")
response.write(b)
end sub
</script>
+++++++++++++++++
可是为什么写不出来呢,是空白啊。