for*_*has 19 asp.net asp.net-membership asp.net-mvc-4
在我的.NET MVC 4中,我添加了一个全局过滤器以保护我的控制器.这是使用:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new System.Web.Mvc.AuthorizeAttribute());
}
Run Code Online (Sandbox Code Playgroud)
这是从我的Global.cs类调用的.
我的Web.config文件包含标准配置:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我的登录操作被装饰,[AllowAnonymous]以允许匿名用户登录.
到目前为止,一切都很好.这是我的登录操作:
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
Run Code Online (Sandbox Code Playgroud)
现在,我想添加一个重置密码页面,就像匿名用户可以使用登录页面一样.我创建了我的动作(在Login动作的同一控制器下)并用装饰装饰它[AllowAnonymous]:
[AllowAnonymous]
public ActionResult ResetPasswordForUser(string message = "")
{
ViewBag.message = message;
return View();
}
Run Code Online (Sandbox Code Playgroud)
然后创建相应的视图.
我将此链接添加到我的登录页面:
@Html.ActionLink("Forgot your password?", "ResetPasswordForUser", "Account")
Run Code Online (Sandbox Code Playgroud)
在运行时,当我使用匿名用户单击此链接时,我会进入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>
}
Run Code Online (Sandbox Code Playgroud)
Ali*_*lay 11
是否有可能ResetPasswordForUser视图使用的_Layout文件正在调用Controller中的Action(例如在菜单中?),该文件尚未被装饰AllowAnonymous?
这会导致这种行为.
| 归档时间: |
|
| 查看次数: |
13530 次 |
| 最近记录: |