Search code examples
c#asp.netasp.net-mvcactionlink

How to configure ActionLink format to drop the subdirectory?


Let's say the domain that is mapped to my root hosting directory is example.com. GoDaddy forces mapping of other domains to subdirectories of the root. For example, my second domain, example1.com, is mapped to example.com/example1.

I uploaded my ASP.NET MVC site to such a subdirectory, only to find that ActionLinks that are for navigation have the following format:

http://example1.com/example1/Controller/Action

In other words, even when I use the domain that is mapped to the subdirectory, the subdirectory is still used in the URL. I want to change the format of my ActionLinks.

However, I noticed that I can also access the same path by going to:

http://example1.com/Controller/Action

(leaving out the subdirectory)

I want to have my ActionLinks automatically drop the subdirectory, as it is not required.

Is this possible without changing the ActionLinks into plain-old URLs?


Solution

  • No, I don't think so, as an action link mainly works to render the controller/action. The other work around, if you have install access for the server, is to use an URL Rewriting tool like iirf.codeplex.com, which is free and works pretty good. There may be some other unintended consequences with rewriting though, depending on what you are doing.

    HTH.