Running ASP.NET MVC in a subdomain causes Html.ActionLink to display broken links

I am running MVC in a subdomain
http://test.domain.com , which points to the / Test directory in my webhost4life account.

Html.ActionLink("About", "About", "Home") 

he refers to

http://test.domain.com/Test/Home/About - which gives 404

link should be.

http://test.domain.com/Home/About

Is there a way to override ActionLink to omit / Test to render?

thanks


Experiment 1

I added a route to the table like this ...

 routes.MapRoute( "Test", // Route name "Test/{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); 

and now the action link displays such links. http://test.domain.com/Test/Test/Home/About/ when clicked, it does not give 404, but gives a Home control About the action.

Result

No longer broken links, but the site displays ugly URLs.

+4
source share
1 answer

For a site that uses many subdomains, I use the excellent MVC extension from ITCloud called UrlRouteAttribute. It allows you to assign a route for each action as an attribute that defines the path and name. I expanded this to allow fully qualified paths - so as to include the domain / subdomain to which the controller should connect. If this interests you, I’ll upload a copy somewhere.

0
source

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


All Articles