MVC5在web.config中放置身份验证表单的位置?

use*_*351 2 c# asp.net asp.net-mvc forms-authentication asp.net-mvc-5

在这个标题之后,在我的web.config中,它由VS 2012生成.

现在,我不知道我把下面的代码放在web.config中我看到有人把它放进去<system.web>但是在我的web.config中它只有<system.web.webPages.razor><system.webServer>.当我把这个代码放在web.config中的某处时,我收到一个错误<authentication mode="Forms">:

有代码:

<authentication mode="Forms">
    <forms loginurl="~/Comfirm/Login" timeout="2880"></forms>
</authentication>
Run Code Online (Sandbox Code Playgroud)

Nko*_*osi 7

您将它放在错误的web.config文件中.有两个web.config文件.一个在Views文件夹中,一个在站点的根目录中.将它放在system.web站点根目录中的web.config文件的标记中

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings  />
  <appSettings >
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="owin:AutomaticAppStartup" value="true" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>      

  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Comfirm/Login" timeout="2880" />
    </authentication>
  </system.web>

  <!--other configuration-->
<configuration>
Run Code Online (Sandbox Code Playgroud)