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”是“命名空间”,但用作“类型”

4

2 回答 2

1

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; 
于 2010-05-16T04:52:11.877 回答
0

您给出的错误是正确的, System.Web.Configuration 是命名空间而不是类型,因此无法实例化。

如果我没记错的话,你想使用 System.Web.Configuration.WebConfigurationManager 类型。

编辑:MSDN

于 2010-05-16T04:52:48.963 回答