在我的.NET MVC 4中,我添加了一个全局过滤器,以保护我的控制器。
这是使用:
这是使用:
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new System.Web.Mvc.AuthorizeAttribute()); }
这是从我的Global.cs类调用的。
我的Web.config文件包含一个标准配置:
<authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication>
我的登录操作用[AllowAnonymous]装饰,以允许匿名用户登录。
迄今为止,一切都很好。这是我的登录操作:
[AllowAnonymous] public ActionResult Login(string returnUrl) { ViewBag.ReturnUrl = returnUrl; return View(); }
现在,我想添加一个重置密码页面,也就是登录页面应该可以给匿名用户使用。我创建了我的动作(在同一个登录操作的控制器下),并用[AllowAnonymous]装饰进行装饰:
[AllowAnonymous] public ActionResult ResetPasswordForUser(string message = "") { ViewBag.message = message; return View(); }
然后创建相应的视图。
@Html.ActionLink("Forgot your password?","ResetPasswordForUser","Account")
在运行时,当我使用匿名用户单击此链接时,我会获得ResetPasswordForUser操作,但是当返回视图时,将会调用Login操作,我永远无法实现所需的视图。由于某些原因,即使我使用[AllowAnonymous]装饰,我的请求也被截获。
我在这里遗漏了什么吗?
提前致谢
UPDATE1:
根据Darin Dimitrov请求添加我的ResetPasswordForUser视图:
@using TBS.Models @model TBS.viewmodels.ResetPasswordForUserviewmodel @{ ViewBag.Title = "Reset Password"; } @using (Html.BeginForm()) { @Html.ValidationSummary(true) <table class="edit-table rounded bordered" style="width: 400px"> <tr> <td class="label-td"> @Html.LabelFor(m => m.Username) </td> <td> @Html.TextBoxFor(m => m.Username) @Html.ValidationMessageFor(model => model.Username) </td> </tr> <tr> <td class="label-td"> @Html.LabelFor(m => m.Password) </td> <td> @Html.Password("Password") @Html.ValidationMessageFor(model => model.Password) </td> </tr> <tr> <td colspan="2" style="text-align: center"> <input type="submit" value="Reset" /> </td> </tr> </table> }