Posts Tagged 'ExcludeFilter'

ASP.NET GlobalFilters, except this one page

If you are an ASP.NET web dev, you probably know about GlobalFilters.  You can apply an ActionFilter attribute globally.  It’s super useful for things like RequireHttps.  Unless you have one page that you want to exclude from that requirement.  Maybe you have AuthorizeAttribute sprinkled around because everything on your site is secure except, obviously, the login page.  Maybe, like me, you have a health check page that you want accessible via HTTP, while everything else is forced to HTTPS, or maybe there is some other use case.  At any rate, I found a good solution, implemented it, and then had to remove it because things took a different direction.  So, I am writing this mostly so I don’t forget about it, because it’s a pattern that I’ve wondered about before and never found a good answer.

Searching for what others have done in this case is actually a little difficult.  The terms for what you want to accomplish – filter, exclude, except – are all pretty generic.  The specific ASP.NET classes and fields are subjects of many unrelated articles, so that doesn’t really help.  Phil Haack has an interesting approach, but ultimately, I prefer declaring rules or exceptions inline as attributes. What I had adapted, before pulling it back out, was a nice approach outlined by Ori Calvo.

If you need to implement a similar setup, check out both approaches, and see if one of them will work for you!


Posts

June 2017
S M T W T F S
« Jun    
 123
45678910
11121314151617
18192021222324
252627282930  

del.icio.us bookmarks

Thanks

I would like to thank Mike Hellrich for hosting a couple redirects for me while I sort out my web server problems.