ASP.NET MVC ActionLink vs. URL Rewrite

There is an ASP.NET MVC 2 web application that can be called myapp.com. I need dynamic subdomains (user created categories) like something.myapp.com. So I configured to rewrite the URL by rewriting the rules something.myapp.com -> myapp.com/something (which is processed by MVC as follows ..). But the first ActionLink throws an exception

System.Web.HttpException: Cannot use host .. to exit top directory

because obviously the url for it is still something.myapp.com. Is there an elegant solution for this? I don't want to redirect (I want to save something.myapp.com url in browser). I also don't like the idea of โ€‹โ€‹writing a custom ActionLink, the most basic in MVC ...

thanx guys :)

Roman

+4
source share
1 answer

The first thing you need to understand is the difference between routing and rewriting. This is best described on this blog:

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

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

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

But in order to more accurately answer your question, you need to make sure that the Rewriter URL is processed before routing, so that everything will be changed and normalized for you ahead of time.

+2
source

Source: https://habr.com/ru/post/1307013/


All Articles