开发者

How do I get my asp.net MVC application to recognize the stylesheet on the live server?

开发者 https://www.devze.com 2023-01-01 14:31 出处:网络
I\'ve been building my sample asp.net application using VWD2008 and the development virtual server that comes with that. I got to the point that I want to make sure that the application behaves correc

I've been building my sample asp.net application using VWD2008 and the development virtual server that comes with that. I got to the point that I want to make sure that the application behaves correctly on the live server, so I went ahead and published it. Everything seems to working great accept for the stylesheets. None of the styles are being applied to the page. I double checked the link to the stylesheet and I double checked the server location. Everything seemed fine and it was identical to the version on my virtual server.

The link is: <link rel="Stylesheet" type="text/css" href="/Content/Site.css" />

When I try to browse to the stylesheet (http://myd开发者_如何学Comain.com/Content/Site.css) I get this error:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Content/Site.css

Do you guys have any idea what could be causing this?


Edit

I went ahead and create a test.html and threw it into the root of the live server.

<!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>

when I browse to this location (mydomain.com/test.html) I get another 404 error. Specifically, I looked at the source of the error page and found this:

[HttpException]: The controller for path '/test.html' was not found or does not implement 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)

It seems that asp.net is still using routing when I request a regular html or css file. is there any way around this. Is there a server setting or somthing I can change in config or routing?


Always use html helpers when working with urls:

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

Or even better with MVCContrib:

<%= Html.Stylesheet("~/Content/Site.css") %>


Try "../../Content/Site.css", it might require a relative path from the current Master page (probably /Views/Shared) to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消