views:

299

answers:

2

I'm deploying a MCV 1.0 project on a web server running IIS6. (not by my choice) I've thru Steve Sandersons article Here and Phil Haack's article but I'm still having probelms.

Right now I'm trying to implement Option 2 from Steve Sandersons article. The main problem I'm having is with the Home link not rendering correctly. For Instance, in my Site map I have the follwoing:

<%= Html.ActionLink("Home", "Index", "Home") %>

this renders on the pages as http://servername/JCIMS_Orange/Home.mvc which is NOT correct.

HOWEVER THIS LINK:

<%= Html.ActionLink("About", "About", "Home") %>

renders as... http://servername/JCIMS_Orange/Home.mvc/About which is correct

My Global.asax RegisterRoutes function looks like:

        public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}.aspx/{action}/{id}",                      // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

        routes.MapRoute(
            "Default2",                                              // Route name
            "{controller}/{action}/{id}",                            // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );
    }

Can anyone tell me why my Home link will not render correctly? I have repeated this error Both on my localhost running on WinXP and on my web server running Win2003 Server.

Appreciate any suggestions or pointers

+1  A: 

Why is http://servername/JCIMS_Orange/Home.mvc not correct? What were you expecting it to be?

Edit: The parameter defaults in your route definition are telling the system that Index is not needed in the route. You could try simply setting the action parameter default to an empty string. That should force the generated urls via Html.ActionLink to include the action name even for the Index action.

routes.MapRoute(
        "Default",                                         // Route name
        "{controller}.mvc/{action}/{id}",                  // URL with parameters
        new { controller = "Home", action = "", id = "" }  // Parameter defaults
    );

However, I don't think that's the best solution. If your images and css aren't working without the action name, then it sounds like you're not referencing the path correctly. Could you provide an example of one of your image links and maybe your css file link? Without seeing what they look like, I can suggest that they should start with "/".

You'll want to fix those links so that when you're using a route url that contains an id parameter they will work for that instance also. (e.g. http://servername/JCIMS_Orange/Products.mvc/Details/5)

Edit 2: Because your site is contained in a subfolder, you need to include that subfolder in your image and css paths. Starting a relative URL with "/" means it's right after the server name. Using "../" means it's relative to the current path, which as you've seen doesn't work with the default MVC routing because for different actions your url has different numbers of elements.

Including your subfolder path should work perfectly in every situation. Like this:

<img src="/JCIMS_Orange/Content/images/JCIMS_Banner.png" alt="JCIMS Banner" />
Dennis Palmer
I tried it with both .aspx and .mvc and neither works.. so right the route is set to .ASPXI guess I'm expecting http://servername/JCIMS%5FOrange/Home.aspx/IndexIf I type that URL in the address bar the page works fine. The http://servername/JCIMS%5FOrange/Home.apsx URL gets me to the page but noimages show up and none of my css is working.-MARK-
Mark Buckley
http://servername/JCIMS_Orange/Home.aspx gets me to my homepage and all my menu link work, but none of the CSS or Graphics work...My Site.Master has the following <img src="../../Content/images/JCIMS_Banner.png" alt="JCIMS Banner" />I've also tried...<img src="../Content/images/JCIMS_Banner.png" alt="JCIMS Banner" />and I've also tried...<img src="/Content/images/JCIMS_Banner.png" alt="JCIMS Banner" />Content is off the root of the web site. This seems like it should be fairly simple to resolve...but right now it's kicking my a$$ :)
Mark Buckley
OK... Your Edit 2 is working fine. By putting the link in the Site Master in that manner appears to be working fine. Thanks Again for all the assistance.
Mark Buckley
You're welcome. Please don't forget to vote for and/or accept the answer. Thanks!
Dennis Palmer
A: 

Dennis,

Thank you for your responses. Between your answer and some more playing around I was able to get my CSS to work.

I used this in my Global.asax file

   routes.MapRoute(
               "Default",
               "{controller}.aspx/{action}/{id}",
               new { controller = "Home", action = "", id = "" }
             );

        routes.MapRoute(
          "Root",
          "",
          new { controller = "Home", action = "", id = "" }
        );

In addition I had to CSS links in each View file. And the graphic had to be referanced using ../ like so...

<img src="../Content/images/JCIMS_Banner.png" alt="JCIMS Banner" />

For now it appears that everything is working. Thank You for your assistance.

-MARK-

Mark Buckley
Your CSS will break again as soon as you have a url with an {id} section. I'll edit my answer again with how the Content files should be referenced.
Dennis Palmer