Asp.net System.Web.Configuration.WebConfiguration Manager.OpenWebConfiguration
我有一个从VS2008到VS2013的网络项目Asp.net System.Web.Configuration.WebConfiguration Manager.OpenWebConfiguration,asp.net,vb.net,.net-remoting,Asp.net,Vb.net,.net Remoting,我有一个从VS2008到VS2013的网络项目 代码在2008年运行良好,但在2013年运行时出错 从名为myWebPages的启动项目中,代码将读取同一解决方案中名为myRemotingService的不同项目中的web.config 以下是部分代码: Dim rootWebConfig1 As System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManage
代码在2008年运行良好,但在2013年运行时出错 从名为myWebPages的启动项目中,代码将读取同一解决方案中名为myRemotingService的不同项目中的web.config 以下是部分代码:
Dim rootWebConfig1 As System.Configuration.Configuration
rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/myRemotingService")
varConnectionString = rootWebConfig1.AppSettings.Settings.Item("ConnectionString").Value 'Error on this line
但是当我将web.config从myRemotingService复制到myWebPages时。并将代码更改为:
rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/myWebPages")
varConnectionString = rootWebConfig1.AppSettings.Settings.Item("ConnectionString").Value
工作正常,但我希望web.config放在myRemotingService中,因为我将构建更多类似项目的myWebPages
代码有什么问题
谢谢
错误是:对象引用未设置为对象的实例
我还运行一些从互联网上获得的代码
rootWebConfig1 =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/myRemotingService")
Dim appSettings As KeyValueConfigurationCollection =
rootWebConfig1.AppSettings.Settings
Console.WriteLine("[appSettings for app at: {0}]", "/myRemotingService")
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
但是appSettings.count的长度是0我通过放置~字符得到它
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/myRemotingService")
它现在正在工作。但2013年运行时出现错误。错误是什么?错误是:对象引用未设置为对象的实例可能与的实例重复