如果不符合某些条件(例如HttpContext.Current.Request.Form [“key”]。toString()),我希望锁定对html页面的访问(例如./manual/manual_A/index.html) 。 .Equals(“a”)),我希望重定向到特定的视图(例如./errorPage/),否则继续(例如/ index)。 In register Route I add:如何限制对ASP.NET MVC中某些页面的访问?
routes.MapRoute(
"ErrorPage",
"errorPage/",
new { controller = "Home", action = "ErrorPage" }
);
routes.MapRoute(
"Path",
"{*_request}",
new { controller = "Home", action = "Index" }
);
用于读取所有请求。 在控制器首页
[CustomAuthorize]
public ActionResult Index()
{
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(!condition)
filterContext.Result = RedirectToAction("PageError");
}
OnActionExecuting执行每个请求,然而,RedirectToAction不会发生。 任何提示我做错了什么?
你redirectToAction和你的路由的行动不匹配,你可能也想检查一下(PageError!= ErrorPage) – Tommy 2010-10-07 13:50:32
你是否绝对肯定你的条件正在评估为false?你可以在调试器下验证它吗?另请记住,授权在其他操作过滤器之前发生。如果您的[CustomAuthorize]挂钩了OnAuthorization,您可能实际上希望从该过滤器中设置Result,而不是使用单独的操作过滤器执行此操作。 – Levi 2010-10-07 16:54:52
嗨,我找到了解决我的问题。在白天把代码提供。感谢大家的建议。 – user468451 2010-10-08 04:36:08