mvc 5形成验证错误

时间:2015-09-19 12:11:02

标签: asp.net asp.net-mvc forms-authentication

我想实现表单授权是我的应用程序。

在我的控制器中我设置:

 FormsAuthentication.SetAuthCookie(loginVm.use_email, loginVm.RememberMe);

然后在我看来:

if (Request.IsAuthenticated)

我得到了我的Request.IsAuthenticated总是假的,所以我尝试在webconfig中添加以下这些行。

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

然而,我遇到了错误:

 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.

我在调试模式localhost下运行,我该怎么做才能让它按照你的方式运行

感谢您的帮助

干杯

1 个答案:

答案 0 :(得分:0)

我找到了答案,不知怎的,我在视图文件夹中得到了另一个web.config文件,所以我将其删除:),现在工作正常