在一个子目录中运行ASP.NET MVC应用程序,获得404错误 [英] Running ASP.NET MVC application in a subdirectory, getting 404 errors

查看:140
本文介绍了在一个子目录中运行ASP.NET MVC应用程序,获得404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ASP.NET MVC的应用程序。我把它部署到晶科技服务器(因此,不能直接访问IIS控制面板)。

I have an application that uses ASP.NET MVC. I have it deployed to a Crystal Tech server (hence, no direct access to IIS control panel).

Initialy这是在根目录下运行,一切都OK。然后,客户端决定,它需要在一个子目录中运行。我有移动应用和家庭的索引页面出现,但所有其他网页试图访问在原来的根目录下的控制器/动作/页/视图。 (使用../controller/action即相对于mysite.com/controller/action)我不明白这一点,因为引用都是上下文。

Initialy this was running in the root directory and everything was OK. The client then decided that it needed to run in a subdirectory. I moved the app there and the home index page comes up, but every other page tries to access the the controller/action/page/view in the original root directory. I don't understand this, since the references were all contextual (i. e. using ../controller/action as opposed to mysite.com/controller/action).

我是不是做错了什么吗?我有哪些选择?

Am I doing something wrong here? What are my options?

谢谢,
詹姆斯

Thanks, James

推荐答案

我会用UrlHelper生成的链接。这将确保它们相对于应用程序的路径。

I would use the UrlHelper to generate the links. This would ensure that they are relative to the application path.

<a href="<%= Url.Action( "action", "controller" ) %>">Link Text</a>

<img src="<%= Url.Content( "~/images/myimg.jpg" ) %>" alt="My Image" />

这篇关于在一个子目录中运行ASP.NET MVC应用程序,获得404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆