开发者

ASP.NET MVC ActionLink vs. URL Rewrite

开发者 https://www.devze.com 2022-12-27 04:00 出处:网络
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

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 direct开发者_JAVA技巧ory

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号