Search code examples
asp.net-mvciis-7t4mvc

Broken Images on IIS7


I have a ASP.NET MVC site and it works just fine when I run it locally. Once I deploy that site to IIS 7 all links to resources are broken (ie. script files, images, css files). Could this be a route issue or would it be an IIS setting?

Here are my routes:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("elmah.axd");
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Search",
        "Basic/Page/{page}",
        new { controller = "Search", action = "Basic" }
    );

    routes.MapRoute(
        "Default",                                                                          // Route name
        "{controller}/{action}/{id}",                                                       // URL with parameters
        new { controller = MVC.Welcome.Name, action = MVC.Welcome.Actions.Index, id = "" }  // Parameter defaults
    );
}

EDIT:

I reference all content using T4MVC template. The template is correct when it specifies the paths with ~/content/. The problem is that when the html is generated the output doesn't include the "~" it is just /content/.

<img src="<%= Links.Content.Images.logo_png %>" alt="Logo" />

<img src="/Content/Images/logo.png" alt="Logo" />

NOTE:

The issue actually was that there is something wrong with this line in web.config. Turns out the January 1st 2011 is not a Friday but Saturday. For some reason it still didn't like that line.

<clientCache httpExpires="Fri, 1 Jan 2011 15:30:00 UTC" cacheControlMode="UseExpires"/>

Changing it to this works just fine;

<clientCache cacheControlMode="UseExpires" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />

Adding it here in hopes that it helps others with this issue.

Thanks!


Solution

  • It's unlikely to be a route or IIS setting. The times I've seen this is generally because either the resources are unavailable, ie not there.

    Also sometimes security on the folder(s) you are trying to access has been set and the default .net user has not been granted access.

    Paths to the resources are not coded correctly. using ~/content instead of /content or even ../../..etc might help.