James
James

Reputation: 31778

MVC ~/ not resolving to application root in virtual directory

I have multiple websites hosted on the same server with structure as follows:

http://primary-domain.com/hostedsites/MVCWebApplication1/ = http://MVCWebApplication1.com/

http://primary-domain.com/hostedsites/MVCWebApplication2/ = http://MVCWebApplication2.com/

...

The problem is, all ~/ references made in a hosted site (i.e. MVCWebApplication1, MVCWebApplication2, etc) resolve to

http://MVCWebApplication1.com/hostedsites/MVCWebApplication1/

and not

http://MVCWebApplication1.com

Please note:

I already have the following my web.config:

<rule name="Remove Virtual Directory">
  <match url=".*" />
  <action type="Rewrite" url="{R:0}" />
</rule>

How can I fix this?

Upvotes: 1

Views: 723

Answers (2)

Jacques Snyman
Jacques Snyman

Reputation: 4300

You just need to convert your virtual directories to applications in IIS.

Upvotes: 0

James
James

Reputation: 31778

What I ended up doing was using a bunch of work arounds:

In web.config:

<rewrite>
  <rules>
    <rule name="Remove Virtual Directory">
      <match url=".*" />
      <action type="Rewrite" url="{R:0}" />
    </rule>
  </rules>
</rewrite>

And instead of creating links like this:

<a href="~/Help">Help</a>

doing this:

@Html.ActionLink("Help", "Help") // This seems to create clean urls

Upvotes: 1

Related Questions