MVC5 在 web.config 中将身份验证表单放在哪里?
MVC5 Where to put authentication forms in web.config?
下面这个标题,在我的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>
您需要将 <system.web>
添加到配置中并放置身份验证部分 within it:
<system.web>
<authentication mode="Forms">
<forms loginurl="~/Comfirm/Login" timeout="2880"></forms>
</authentication>
</system.web>
如果我没记错的话,VS 只制作它会使用的标签。您是否尝试过创建 <system.web>
?它不会自动为配置生成空白部分。
<system.web>
<authentication mode="Forms">
<forms loginurl="~/Comfirm/Login" timeout="2880"></forms>
</authentication>
</system.web>
您将其放入错误的 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>
在 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" 是平均一天
下面这个标题,在我的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>
您需要将 <system.web>
添加到配置中并放置身份验证部分 within it:
<system.web>
<authentication mode="Forms">
<forms loginurl="~/Comfirm/Login" timeout="2880"></forms>
</authentication>
</system.web>
如果我没记错的话,VS 只制作它会使用的标签。您是否尝试过创建 <system.web>
?它不会自动为配置生成空白部分。
<system.web>
<authentication mode="Forms">
<forms loginurl="~/Comfirm/Login" timeout="2880"></forms>
</authentication>
</system.web>
您将其放入错误的 web.config 文件中。有两个 web.config 个文件。一个在 Views
文件夹中,一个在站点的根目录中。将它放在站点根目录
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>
在 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" 是平均一天