1

我编写了一个 ASP.NET MVC3 Web 应用程序,它在 Visual Studio 开发 Web 服务器中完美运行,并在特定的 IIS Web 服务器上运行。

我已在另一个 IIS Web 服务器上成功发布了相同的 Web 应用程序。除了奇怪的行为外,它运行良好。

我的控制器操作毫无问题地返回内容,但未呈现布局页面。我最终只有控制器操作返回的内容。

我错过了什么?

4

1 回答 1

2

I bet you have hardcoded the urls to scripts and CSS in your view instead of using Url helpers. You wrote:

<link href="/Content/Site.css")" rel="stylesheet" type="text/css" />

instead of the correct way:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

or you wrote:

<script src="/Scripts/jquery-1.5.1.min.js"" type="text/javascript"></script>

instead of the correct way:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>

Now go ahead and search for all places where you have hardcoded urls like this and replace them with urls generated by helpers.

The reason why your site doesn't work when deployed in IIS is because in IIS there's a probably a virtual directory that you have to take into account. So the correct address is http://example.com/myappname/content/site.css whereas when running locally there's no such directory http://localhost:1234/content/site.css.

于 2012-06-19T05:59:11.653 回答