首页 > 解决方案 > MVC 无法重定向到自定义登录 url

问题描述

我在 web.config 上设置了以下表单身份验证属性。

 <authentication mode="Forms" >
  <forms loginUrl="~/Account/VerifyCode" timeout="2880">
    <credentials passwordFormat="Clear">
      <user name="admin" password="admin"/>
    </credentials>
  </forms>
</authentication>

但总是当导航到用 [Authorize] 属性装饰的控制器时,我总是被重定向到 ~/Account/Login?ReturnUrl=%2FProduct%2FCreate ,而不是我在 web.config 中设置的方法(表示验证代码)。

任何人都知道为什么会这样,以及如何将其重定向到我在 web.config 中指定的方法?

标签: c#asp.net-mvcforms-authentication

解决方案


试试下面的代码而不是你的代码

<authentication mode="Forms">
  <forms loginUrl="~/Account/VerifyCode" timeout="2880"/>
 </authentication>

推荐阅读