2017-02-22 36 views
1

隨着這個稱號,在我的web.config中,其由2012年VSMVC5哪裏把認證表單放在web.config中?

現在產生的,我不知道在哪裏,我把在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> 
+1

你正在把它放在錯誤的web.config文件中。有兩個web.config文件。一個在'Views'文件夾中,另一個在網站的根目錄中。把它放在站點根目錄下配置文件的system.web標籤中。 – Nkosi

+0

@Nkosi哦,我的上帝,9:36 pm,我的錯誤。它解決了。非常感謝 ! – user1465351

回答

4

你把它放在錯誤的web.config文件中。有兩個web.config文件。一個在Views文件夾中,另一個在網站的根目錄中。把它放在web.config文件的system.web標籤在站點根

<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> 
+0

非常感謝。我的錯 ! – user1465351

1

您需要添加<system.web>的配置,並把識別部分within it

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

我嘗試了一下,但出現錯誤:在應用程序級別之外使用註冊爲allowDefinition ='MachineToApplication'的節是錯誤的。此錯誤可能是由於虛擬目錄未被配置爲IIS中的應用程序。 – user1465351

+0

你是否已將它添加到應用程序根目錄下的web.config中? – stuartd

+0

uhm,我在標籤後添加了標籤 – user1465351

1

如果我沒有弄錯,VS只會製作它將使用的標籤。你有沒有試過創建<system.web>?它不會自動生成配置的空白部分。

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

我嘗試了一下,但出現錯誤:在應用程序級別之外使用註冊爲allowDefinition ='MachineToApplication'的節是錯誤的。此錯誤可能是由於虛擬目錄未被配置爲IIS中的應用程序。 – user1465351

+0

@ user1465351如果您遇到了該錯誤,那麼您正在使用錯誤的'web.config'文件。 – Andrew

0

在MVC 5的默認值是:

<system.web> 
<authentication mode="None" /> 
<compilation debug="true" targetFramework="4.7.1" /> 
<httpRuntime targetFramework="4.7.1" /> 
<httpModules> 
    <add name="ApplicationInsightsWebTracking" 
    type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, 
Microsoft.AI.Web" /> 
</httpModules> 
</system.web> 

你可以注意到線

<authentication mode="None" /> 

將其更改爲:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/Login" timeout="1440" /> 
</authentication> 

並且timeout =「1440」其平均值有一天