我正在学习ASP.NET MVC。我的MVC版本是5.2.2.0。
我在Employee控制器的Index()方法中附加了Authorize属性。
在Web.config文件中,我将authentication标签数据更改为以下内容:
<system.web>
<authentication mode="Forms">
<forms loginurl="~/Authentication/Login"></forms>
</authentication>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
期望的是当访问localhost:port/Employee/Index时,用户应该被重定向到localhost:port/Authentication/Login
但实际上它却被重定向到了localhost:port/Account/Login
根据其他链接的情况,我尝试了以下方法:
1.添加
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
<add key="loginUrl" value="~/Authentication/Login" />
<add key="PreserveLoginUrl" value="true" />
将内容添加到Web.config的appSettings部分
2.将IIS 8匿名身份验证从指定用户更改为应用程序池标识
3.当上述两种方法都不起作用时,我将身份验证标签更改为
<authentication mode="Windows" />
但是没有一个有效。
编辑 不要执行我上面提到的1、2、3步骤。只需按照答案中提到的更改即可。