Relative Path tilde (~) not working in ASP.NET MVC 4

谁说胖子不能爱 提交于 2019-12-08 01:52:40

问题


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>

回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!