ここでの仕事: Web.Configの特定のキーに基づいて特定のURL「コントローラ/アクション」を削除したい 私はカスタムフィルタを作成しようとしました属性が、私は「OnActionExecutingが無限ループ の原因」という別の問題を発見し、実際に私は、このソリューション「ASP.NET MVC 3 OnActionExecuting causes infinite loop」で確信していたが、私はまだ解決策を見つけることができませんカスタム属性|| Web.Config内の特定のURLにアクセスするのを防ぐ
のWeb.Config:
を<add key="Delegation" value="true" />
私のコントローラー:ログインユーザーが承認されているかどうかを確認し、このユーザーがこのコントローラーの資格があるかどうかを確認します。
[MyAuthorize("EdgeEngineGroups")]
[Edge.Models.FilterAttribute]
マイろ過クラス:
public class FilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string Delegation = "";
Delegation = System.Configuration.ConfigurationManager.AppSettings["Delegation"].ToString();
if (string.IsNullOrEmpty(Delegation) != null)
{
if(Delegation.ToLower() == "true")
{
var controllerName = filterContext.RouteData.Values["controller"];
var actionName = filterContext.RouteData.Values["action"];
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary{{ "controller", controllerName },
{ "action", actionName }
});
}
else
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary{{ "controller", "AccessDenied" },
{ "action", "NotFound" }
});
}
}
else
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary{{ "controller", "AccessDenied" },
{ "action", "NotFound" }
});
}
base.OnActionExecuting(filterContext);
}
}
それはキーが「偽」である右のとき、それが見つからないページにリダイレクトしますが、キーは真であるとき、それは私にリダイレクト作品コントローラーが毎回フィルター属性を検出します。
このエラーを修正する方法があるか、メインタスクの別の解決策があるかどうかを知りたいと思います。