大佬教程收集整理的这篇文章主要介绍了ASP.NET MVC 4全局授权过滤器强制在AllowAnonymous操作上登录,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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> }
以上是大佬教程为你收集整理的ASP.NET MVC 4全局授权过滤器强制在AllowAnonymous操作上登录全部内容,希望文章能够帮你解决ASP.NET MVC 4全局授权过滤器强制在AllowAnonymous操作上登录所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。