views:

201

answers:

1

Hello, here is the issue : There is a ASP.NET MVC 2 web app, lets call it myapp.com. I want dynamic subdomains (user created categories) like something.myapp.com. So i have set up URL rewrite with rule rewriting something.myapp.com -> myapp.com/something (which is handled by MVC next..). But, the first ActionLink throws an exception

System.Web.HttpException: Cannot use a leading .. to exit above the top directory

because, obviously, the URL is still something.myapp.com for it. Is there any elegant solution for this ? I dont want to redirect (I want to keep URL something.myapp.com in browser). Also I dont like the idea of writing custom ActionLink, some of the most basic stuff in MVC...

thanx guys :)

Roman

A: 

The first thing you have to understand is the difference between Routing and Rewriting. This can best be described by this blog:

http://www.coderjournal.com/2010/03/difference-between-routing-rewriting/

As a follow up to the article a project for editing Routing inline with Rewriting was also created, to help demonstrate the differences and more importantly how they can be used together.

http://www.coderjournal.com/2010/03/editable-mvc-routes-apache-style/

But to answer your question more directly, you need to make sure the URL Rewriter is getting processed before the Routing, so that everything is modified and normalized for you ahead of time.

Nick Berardi