Ich habe eine LoggingAttribute
die Anfrage und Antwort in OnActionExecuted
Methode protokolliert:Action an Controller vs Aktionsmethode
public class LoggingAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext httpContext)
{
//Logger.Log();
}
}
Es zur Validierung der Anfrage ein weiteres Attribut ist und das Rück BadRequest
. Diese Rückantwort von OnActionExecuting
Methode:
public class ValidateModelAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
var modelState = actionContext.ModelState;
if (!modelState.IsValid)
{
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, modelState);
}
}
}
Nun, wenn ich beide diese Attribute auf Action-Methode anwenden, mein BadRequest
s wird nicht angemeldet, aber wenn ich LoggingAttribute
auf Controller-Ebene und ValidateModelAttribute
auf Aktionsmethode anwenden, BadRequest
s angemeldet zu werden (OnActionExecuted
von LoggingAttribute
immer genannt).
Kann jemand bitte erklären dieses Verhalten das heißt OnActionExecuted
genannt zu werden, selbst wenn Aktionsmethode nicht ausgeführt wird, wenn Attribut an Controller angewendet.
sind Sie Bruchstelle auf LoggingAttribute bekommen, wenn Sie beide –
Attribut anwenden Wenn sowohl auf actionmethod Anwendung - Nein. Wenn LoggingAttribute auf Controllerebene und ValidateModetAttribute bei Aktionsmethode - Ja. – ctor
haben Sie verändern die Reihenfolge auf Action-Methode versucht? – programtreasures