O'Reilly logo

ASP.NET MVC 2 Cookbook by Richard Kimber, Andrew Siemer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a blacklist route constraint

Sometimes you want to take control over all of your requests prior to them getting too deep into your application. While you could do this with an HttpHandler or an HttpModule, that wouldn't be very MVC-like. Instead, we will implement this sort of logic in the next step of the pipeline by way of a custom RouteConstraint.

In our example, we will take a look at implementing a blacklist filter, using a wide open wildcard route and a RouteConstraint that checks all requests against a few different types of blacklists. If the user is on the blacklist, we will have the option to route them off our site or to a page in our site specifically for blacklisted folks.

How to do it...

  1. Create a new MVC application.
  2. Open up ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required