我一直在使用VWD2008和随附的开发虚拟服务器构建我的示例asp.net应用程序。我得到了一点,我想确保应用程序在实时服务器上运行正常,所以我继续发布它。一切似乎都很适合样式表。没有任何样式应用于页面。我仔细检查了样式表的链接,然后我仔细检查了服务器位置。一切似乎都很好,它与我的虚拟服务器上的版本相同。
链接为:<link rel="Stylesheet" type="text/css" href="/Content/Site.css" />
当我尝试浏览样式表(http://mydomain.com/Content/Site.css)时,我收到此错误:
>应用程序中的服务器错误。无法找到资源。
描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。
请求的网址:/Content/Site.css
你们有什么想法会导致这种情况吗?
我继续创建了一个test.html并将其扔进了实时服务器的根目录。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>test</title>
<link rel="Stylesheet" type="text/css" href="/Content/Site.css" />
</head>
<body>
<h1>Hi</h1>
</body>
</html>
当我浏览到这个位置(mydomain.com/test.html)时,我得到另一个404错误。具体来说,我查看了错误页面的来源,发现了这个:
[HttpException]:未找到路径'/test.html'的控制器或未实现IController。
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
当我请求常规html或css文件时,似乎asp.net仍在使用路由。有没有办法解决。是否有服务器设置或我可以在配置或路由中更改的内容?
答案 0 :(得分:2)
始终使用html帮助:
<link rel="Stylesheet"
type="text/css"
href="<%= Url.Content("~/Content/Site.css") %>" />
<%= Html.Stylesheet("~/Content/Site.css") %>
答案 1 :(得分:0)
尝试“ ../../ Content / Site.css ”, 它可能需要从当前主页面(可能是/ Views / Shared)的相对路径才能工作。