When I run my project on my machine, it runs on http://localhost:53998/
but when I deploy it to http://test.myserver.com/MyApp/
all links break. I'm using the relative path tilde (~
), so a navigation link would be something like:
<a href="~/SomeCtrl/Index">Some Action</a>
On localhost, this works fine (when root is /
), but when I deploy my project under /MyApp/
it links the action to http://test.myserver.com/SomeCtrl/Index
instead of http://test.myserver.com/MyApp/SomeCtrl/Index
so I always get a 404.
Isn't this what the tilde (~
) should take care of? Am I doing something wrong here?
EDIT:
This works correctly:
@Html.ActionLink("Some Action", "Index", "SomeCtrl")
And this:
<a href="@Url.Action("Index", "SomeCtrl")">Some Action</a>
I had a similar problem, the answer in my case was I had some URL Rewrite settings which were changing the tilde path to point to a different folder. I had to sort out these rewrite rules and it fixed my problem.
来源:https://stackoverflow.com/questions/22452518/relative-path-tilde-not-working-in-asp-net-mvc-4