1

I want to log response http status code in filters? I have an action filter and an exception filter. I can log 500 responses in the exception filter. however the response object I get in the action filter is always 200 because at that time the response body is not written into.

I thought about using middleware however I cannot seem to get the Controller name and Action name in the middleware. Any suggestions?

1 Answer 1

1

I figured this out...

                var endpoint = httpContext.GetEndpoint();
            if (endpoint != null)
            {
                var controllerActionDescriptor = endpoint.Metadata.GetMetadata<ControllerActionDescriptor>();
                if (controllerActionDescriptor != null)
                {
                    var controllerName = controllerActionDescriptor.ControllerName;
                    var actionName = controllerActionDescriptor.ActionName;
                }
            }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.