views:

177

answers:

3

Hello all,

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://mydomain.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"&gt;
<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?

A: 

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

Maxime
I went ahead and tried "../../Content/Site.css" with the same results as the absolute path.
quakkels
The Content folder is located in /Views or /?That link element is located in the master page in /Views/Shared?Try using HttpContext.Current.Request for debugging purposes, especially Path properties, it will help.Also, verify that the resource is really 404 with firebug or fiddle when loading the page.
Maxime
the content folder is in its default location (root)/Content. Firebug does indicate that the error is 404. I placed <%= HttpContext.Current.Request%> on the master page and it printed: System.Web.HttpRequest. I suspect I'm supposed to do something other than just print it :-)
quakkels
+2  A: 

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") %>
Darin Dimitrov
Thanks for the input. <%= Url.Content("~/Content/Site.css") %> returns the same thing in the browser that I had entered before: /Content/Site.css. It still works on the virtual server but not on the live server.
quakkels
Could you post the full **physical** path to this stylesheet? Also what does FireBug says about it?
Darin Dimitrov
@Darin - Sure thing Z:\Standard Sites\test website\Content\Site.css also, I've been trying to get to it from the browser by going to xx.xx.xx.x/Content/Site.css (the ip address xx.xx.xx.x goes to Z:\Standard Sites\test website\)
quakkels
@Darin - Firebug says: HTTP/1.1 404 Not FoundCache-Control: privateContent-Type: text/html; charset=utf-8Server: Microsoft-IIS/7.5X-AspNet-Version: 2.0.50727X-Powered-By: ASP.NETDate: Tue, 01 Jun 2010 16:33:38 GMTContent-Length: 1511
quakkels
Try adding the following in the beginning of your route definitions: `routes.IgnoreRoute("{folder}/{*pathInfo}", new {folder="Content"});`
Darin Dimitrov
@Darin - thanks for continuing to help me troubleshoot. I'll try this out right away. (I'm still stumped as to why the css works on the virtual server and not the live one.)
quakkels
Sweet... That looks like it's working!!!
quakkels
Do you have any idea why I needed to modify Global.asax.cs to get css files to work? If not that's fine. Just wondering if you had any thoughts on it.
quakkels
It's because it seems that the server has a wildcard mapping to the aspnet_isapi filter meaning that every request even for static resources goes through the routing engine. So when you perform the following request: `/content/site.css` because of this wildcard mapping the server tries to locate a controller called `content` and an action called `site.css` which does not exist. By adding the `IgnoreRoute` you basically say that everything that is inside the `Content` folder should be passed along the pipeline and not handled by the routing engine.
Darin Dimitrov
A: 

Did you ever find a solution to this? I'm having the exact same problem when I try to host on a live server, it's almost as if the server isn't hosting the css file.

blackn1ght