我々は、我々はコンテキストを取得することができ、いくつかの傍受を達成するための検証動作をフィルタを使用する必要がある多くの時間がActionExecutingContextで、どのように我々はそれのコンテキストによってアクション、コントローラおよびその他のオブジェクトを得るのですか?レコード:
コードで
[AttributeUsage(AttributeTargets.Method、AllowMultiple = 偽、継承= 真)] パブリック クラスViewLogAttribute:ActionFilterAttribute { 公共 オーバーライド ボイドOnActionExecuting(ActionExecutingContext filterContext) { 塩基.OnActionExecuting(filterContext)。 } }
もっと簡潔な方法:
VAR AREANAME = filterContext.ActionDescriptor.RouteValues [ "領域"]。
VARコントローラ名= filterContext.ActionDescriptor.RouteValues [ "コントローラ"]。
VARてactionName = filterContext.ActionDescriptor.RouteValuse [ "アクション"];
1.名コードの取得制御
MVCで
VARコントローラ名= filterContext.ActionDescriptor.ControllerDescriptor.ControllerName。
力は、MVCのコアを有効にする必要
VARコントローラ名=((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)filterContext.ActionDescriptor).ControllerName。
または使用
filterContext.Controller.GetType()。名前
MVCも可能
VARコントローラ名= HttpContext.Current.Request.RequestContext.RouteData.Values [ "コントローラ"]。
アクション名コードを取得2。
VARてactionName = filterContext.ActionDescriptor.ActionName。
若しくは
VARてactionName = HttpContext.Current.Request.RequestContext.RouteData.Values [ "アクション"];
アクションパラメータ名を取得します。3.
//取得パラメータ配列 VAR arrParameter filterContext.ActionDescriptor.GetParameters =(); //インデックスは、パラメータ名に対応します VARのparamName = arrParameter [0] .ParameterName 。
パラメータの値を取得します。4.
VAR parameterValue = filterContext.Controller.ValueProvider.GetValue(paramNameに).RawValue。
決定されたパラメータ名がキーによって直接ActionParametersによって得ることができる場合、キーはパラメータ名を指し
VAR parameterValue = filterContext.ActionParameters [ "キー名"];