asp.net-mvc – 允许Anonymous在asp.net mvc 3中调用某些操作
发布时间:2020-12-16 04:01:38 所属栏目:asp.Net 来源:网络整理
导读:我有一个名为ForgetPassword的动作.每次匿名尝试检索操作时,他/她都会被重定向到登录页面.以下是我的实现. public ActionResult ForgotPassword(string UserName){ //More over when i place a breakpoint for the below line //its not even getting here r
我有一个名为ForgetPassword的动作.每次匿名尝试检索操作时,他/她都会被重定向到登录页面.以下是我的实现.
public ActionResult ForgotPassword(string UserName) { //More over when i place a breakpoint for the below line //its not even getting here return View("Login"); } 这是我的web.config文件的一部分 <location path=""> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> <location path="Content"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> <location path="Scripts"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> <location path="Images"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> <authentication mode="Forms"> <forms loginUrl="/Home/Login" timeout="5" slidingExpiration="false" /> </authentication> 解决方法
因为你通过使用来拒绝所有人的申请.
<authorization> <deny users="?"/> </authorization> 恕我直言,您不应该使用web.config来控制应用程序的身份验证,而是使用Authorize属性. 在RegisterGlobalFilters方法下的Global.asax文件中添加它 public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new AuthorizeAttribute()); //Added } 或者您也可以使用[授权]装饰您的控制器 [Authorize] public class HomeController : Controller { ... } 如果您使用的是ASP.NET MVC4,则对于需要匿名访问的操作,请使用AllowAnonymous属性 [AllowAnonymous] public ActionResult ForgotPassword() { //More over when i place a breakpoint for the below line //its not even getting here return View("Login");; } 根据Reference,您不能使用路由或web.config文件来保护您的MVC应用程序.保护MVC应用程序唯一受支持的方法是将Authorize属性应用于每个控制器,并在登录和注册操作上使用新的AllowAnonymous属性.根据当前区域做出安全决策是非常糟糕的事情,并会将您的应用程序打开到漏洞中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET – 如何检查浏览器支持html5?
- ASP.NET网站Windows窗体应用程序WCF服务:客户端凭据
- asp.net-core – 控制器生命周期ASP.NET Core WebApi
- asp.net c#中的最佳Audit Trail流程?
- asp.net-mvc – 模拟FormsAuthentication.Authenticate()方
- 异常处理 – 如何处理WebAPI中的控制器构造函数中的异常?
- asp.net-mvc-3 – MVC3中的模型级错误?
- asp.net-mvc – Razor模板,views和angular.js
- asp.net – FormsAuthentication.SetAuthCookie()是否创建一
- asp.net – 文本框在点击输入时关注按钮?
推荐文章
站长推荐
- asp.net-mvc-2 – ASP.NET MVC 2和PRG模式
- asp.net – 将div固定在html中的某一点
- asp.net-mvc-4 – 最小和最大字符串长度的单独错
- asp.net – 使用SignalR编译项目时,我必须做一个
- asp.net-mvc – 将我的网站重定向到mvc中的默认控
- 如何在asp.net中验证日期
- asp.net – 如何使用app_GlobalResource或app_Lo
- asp.net-mvc – CssRewriteUrlTransform没有被调
- asp.net-mvc – TryUpdateModel的实例,ASP .NET
- asp.net-mvc – ASP.NET Core MVC:设置身份cook
热点阅读