添加siteMap后WebConfigurationManager出错

发布于 2024-09-01 08:39:28 字数 776 浏览 5 评论 0原文

我收到此错误:

编译器错误消息: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神妖 2024-09-08 08:39:28

System.Configuration.Configuration 而不是 System.Web.Configuration

        // Get the configuration object for a Web application
        // running on the local server. 
        System.Configuration.Configuration config =
            WebConfigurationManager.OpenWebConfiguration("/~") 
            as System.Configuration.Configuration; 

System.Configuration.Configuration instead of System.Web.Configuration

        // Get the configuration object for a Web application
        // running on the local server. 
        System.Configuration.Configuration config =
            WebConfigurationManager.OpenWebConfiguration("/~") 
            as System.Configuration.Configuration; 
埖埖迣鎅 2024-09-08 08:39:28

您给出的错误是正确的,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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文