Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC5 Where to put authentication forms in web.config?

Following this title, in my web.config, it's generated by VS 2012.

Now, i don't know where i put the below code in web.config through i saw someone put it in <system.web> but in my web.config it have only <system.web.webPages.razor> and <system.webServer>. When i put this code somewhere in web.config I get an error at <authentication mode="Forms">:

There's code :

<authentication mode="Forms">
    <forms loginurl="~/Comfirm/Login" timeout="2880"></forms>
</authentication>
like image 536
Chris H Avatar asked Feb 22 '17 14:02

Chris H


1 Answers

You are putting it in the wrong web.config file. There are two web.config files. one in Views Folder and one in the root of the site. put it in the system.web tag of the web.config file in the site root

<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>
like image 191
Nkosi Avatar answered Nov 05 '22 20:11

Nkosi