相对路径符号(〜)在ASP.NET MVC 4不工作 [英] Relative Path tilde (~) not working in ASP.NET MVC 4
问题描述
在我的机器上运行我的项目,它运行在的http://本地主机:53998 /
但是当我将其部署到 HTTP: //test.myserver.com/MyApp /
所有链接中断。我使用的是相对路径波浪号(〜
),这样的导航链接会是这样的:
< A HREF =〜/ SomeCtrl /索引>有的动作< / A>
在本地主机,这工作正常(当根 /
),但是当我在 / MyApp的/ $ C $部署我的项目C>它链接的行动
http://test.myserver.com/SomeCtrl/Index
而不是 http://test.myserver.com / MyApp的/ SomeCtrl /指数
所以我总是得到一个404。
这不是什么波浪号(〜
)应该照顾?难道我做错了吗?
编辑:
这正常工作:
@ Html.ActionLink(一些行动,索引,SomeCtrl)
和这样的:
< A HREF =@ Url.Action(指数,SomeCtrl)>有的动作< / A>
我有一个类似的问题,在我的情况,答案是我已经被它改变波浪路径指向不同的文件夹的一些URL重写设置。我不得不理清这些重写规则,并将其固定我的问题。
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.
这篇关于相对路径符号(〜)在ASP.NET MVC 4不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!