添加siteMap后WebConfigurationManager出错
我收到此错误:
编译器错误消息:CS0118:“配置”是“命名空间”,但像“类型”一样使用 配置 myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
该代码已经使用了 5 个多月,没有出现此问题,直到今天添加此站点地图代码后才出现此问题。
<siteMap defaultProvider="ExtendedSiteMapProvider" enabled="true">
<providers>
<clear/>
<add name="ExtendedSiteMapProvider" type="Configuration.ExtendedSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
我尝试添加“System.Web”。在“配置”之前,但这也不起作用:
System.Web.Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
错误1“System.Web.Configuration”是“命名空间”,但像“类型”一样使用
I'm getting this error:
Compiler Error Message: CS0118: 'Configuration' is a 'namespace' but is used like a 'type'
Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
This code has been in place for 5+ months without this issues, only today after adding this sitemap code do I have this issue.
<siteMap defaultProvider="ExtendedSiteMapProvider" enabled="true">
<providers>
<clear/>
<add name="ExtendedSiteMapProvider" type="Configuration.ExtendedSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
I tried adding "System.Web." before the "Configuration ", but that did not work either:
System.Web.Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
Error 1 'System.Web.Configuration' is a 'namespace' but is used like a 'type'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
System.Configuration.Configuration 而不是 System.Web.Configuration
System.Configuration.Configuration instead of System.Web.Configuration
您给出的错误是正确的,System.Web.Configuration 是命名空间而不是类型,因此无法实例化。
如果我没记错的话,您想使用 System.Web.Configuration.WebConfigurationManager 类型。
编辑: MSDN
The error you're being given is correct, System.Web.Configuration is a namespace and not a type and so can not be instantiated.
You want to use the type System.Web.Configuration.WebConfigurationManager if my memory serves me correctly.
EDIT: MSDN