views:

32

answers:

1

Hi,

ASP.NET MVC web app that exposes "friendly" URLs:

http://somesite.com/friendlyurl

...which are rewritten (not redirected) to ASP.NET MVC-style URLs under the hood:

http://somesite.com/Controller/Action

The user never actually sees any ASP.NET MVC style URLS. If he requests one, we hard 404 it. ASP.NET MVC is (in this app) an implementation detail, not a fundamental interface.

My question: how do you examine an arbitrary incoming URL and determine whether or not that URL matches a defined ASP.NET MVC path?

For extra credit: how do you do it from inside an ASP.NET-style IHttpModule, where you're getting invoked upstream from the ASP.NET MVC runtime?

Thanks!

+1  A: 

why do you have the "hard" urls in the first place then? just change your routing, it seems kind of odd to rewrite something you have complete control over.

If you can't, you probably want something along these lines

Response.StatusCode = (int)HttpStatusCode.NotFound;
return View("NotFound");
Matt Briggs
Good question. For legacy reasons, mainly. And there are a couple edge cases where doing the URL rewriting via an IHttpModule is a lot easier, or at least more intelligible/maintainable, than doing the equivalent with routes.
James D
Good answer ;-). IMO if routing can all be done in one place, that is the preferred way to do it, but thats just me.
Matt Briggs
edited to give a real answer rather then a "You aren't asking the right question" answer
Matt Briggs