views:

301

answers:

4

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!

+1  A: 

Make sure the build actions are set to Content.

Martin
All the files are set to Content. Good call, I didn't think of that. It must be something else!
Lukasz
happened to me the other day ... a pdf file was not set, and never moved to the server.
Martin
+2  A: 

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.

griegs
So I found the problem, it was the paths. The problem is I am using T4MVC and the path seems correct in the T4 template, it uses the ~/content for the path. But when the site runs the path is /content. Thanks at least I have a place to start.
Lukasz
+1  A: 

Try checking your folder permissions - are you in a non-standard folder (not wwwroot)? Make sure that the IIS_IUSRS group has Read & Execute permissions on the folder and subfolders. If that doesn't work, try changing the permissions to temporarily give Full Control to Everyone, just to see if it's a permissions issue at all.

Dave Cowart
+1  A: 

Not sure I understand the issue. It would be wrong for T4MVC to output the ~/ path to the client, since ~/ is a server side syntax that browsers don't understand. Note that you can change this processing if you like by going to T4MVC.settings.t4, which has:

// You can change the ProcessVirtualPath method to modify the path that gets returned to the client.
// e.g. you can prepend a domain, or append a query string:
//      return "http://localhost" + path + "?foo=bar";
private static string ProcessVirtualPathDefault(string virtualPath) {
    // The path that comes in starts with ~/ and must first be made absolute
    string path = VirtualPathUtility.ToAbsolute(virtualPath);

    // Add your own modifications here before returning the path
    return path;
}

So you can make it return whatever you want, but I don't think returning the ~/ path will help you.

I may be misunderstanding the issue a bit.

David Ebbo