0

This is sort of a broad question, but one I am curious about.

What are some examples of uses for MVC Global filters? I.E.

 public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
        filters.Add(new CustomFilterAttribute());
    }

I have seen many examples of stopwatches which while perfectly legitimate, lacks much real use.

I have also seen a few logging examples which is good, but I was wondering if anyone has any other thoughts on what to implement them for, or places you have used them.

1 Answer 1

1

Most importantly in my opinion is security. You can have security applied to everything by default using a global action filter.

Global injecting of content - html or headers for example.

Sign up to request clarification or add additional context in comments.

2 Comments

Would you do that with the Response.Write() ?
if writing raw html, then yes. otherwise for headers you would use filterContext.HttpContext.Response.Headers

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.