8

将 System.Data.Entity 的组件添加到我的 Web 配置后,出现此错误:在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的部分是错误的。此错误可能是由未在 IIS 中配置为应用程序的虚拟目录引起的。

我删除了 obj 和 bin 文件夹,我删除了行 authentication="windows",尝试重新打开,因为有些人说它有效,我检查了主文件夹中只有 1 个 web.config(实体框架 - 文件夹表格、模型、DAL 和 BLL)...

还有什么其他原因会发生这种情况?我到处搜索,基本上是我发现的上述原因....

这是我的 web.config 如果它有所作为:

    <configuration>
  <connectionStrings>
    <add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
     providerName="System.Data.SqlClient" />
    <add name="CStringVKB" connectionString="Data Source=.;Initial Catalog=VKB;Persist Security Info=True;User ID=websiteservice;Password=websiteservice" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" optimizeCompilations="true" targetFramework="4.0" >
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <!--<authentication mode="Windows">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>-->
     <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>
   <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
  </system.web>
  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

我能做些什么来解决这个问题?

4

3 回答 3

23

基本上,该错误意味着您的其中一个子文件夹中有一个 web.config 文件,该文件具有不应具有的配置元素。这是您的根/仅网络配置文件吗?如果没有,你能把这些也发一下吗?

此外,这听起来很愚蠢,但我会仔细检查您是否在 IDE 中打开网站本身(而不是错误地打开父文件夹)我看到人们花了几个小时试图调试同样的错误,而他们一直不在正确的目录中。

以下是关于如何为 ASP 设置 web.config 层次结构的一个很好的解释,它将帮助您可视化其工作原理: http ://scottonwriting.net/sowblog/archive/2010/02/17/163375.aspx

于 2013-04-24T16:26:09.500 回答
1

显然我的解决方案中有两个 web.config 文件。我正在使用 MVC4,在 Views 下还有另一个配置文件,我在错误的文件中进行了更改。固定在那里帮助了我。

但是您始终可以更改 global.asax 文件中的默认重定向/路由。

于 2014-06-05T19:30:35.367 回答
0

Chris Noreikis 的回答实际上是正确的。但是漏掉了一个重要的细节。如果出于某种原因,您在与最初创建的 VS 版本不同的 VS 版本中打开项目/解决方案,则 VS 将尝试迁移。在此迁移过程中,VS 有时会创建一个名为“backup”或“backup_{#}”的文件夹。即使您撤消此迁移强制进行的未决更改,这些目录仍然存在。

这些目录的存在在某些情况下(如我的)是导致此错误的原因。删除这些目录将消除问题。

我希望这可以节省我在这个问题上浪费的无数时间。

于 2015-10-06T18:33:22.407 回答