URL Routing in IIS 5.1

Last post 02-19-2008 3:52 PM by sliderhouserules. 3 replies.

Sort Posts:

  • URL Routing in IIS 5.1

    02-19-2008, 12:27 PM
    • Member
      141 point Member
    • taq
    • Member since 06-28-2006, 4:17 PM
    • Posts 62

     I am having a great amount of difficulty deploying my MVC application to a machine running IIS 5.1 (XP Pro). I posted about it at the end of this thread: http://forums.asp.net/t/1193250.aspx but since that thread is marked as answered, it is unlikely to get viewed.

    I wont repeat what I posted in the previous thread, but I do have a question that hopefully someone here can answer.

    When I change the route rules in global.asax.cs to look like this:

    RouteTable.Routes.Add(new Route
                {
                    Url = "[controller].mvc/[action]/[id]",
                    Defaults = new { action = "Index", id = (string)null },
                    RouteHandler = typeof(MvcRouteHandler)
                });

    Are all of my URLs in the application suppose to contain the .mvc extension? To clarify, in IIS 5.1 with the new route rules (and all the other hackery needed for IIS 5.1) if I manually change the URL in the browser address bar to include the .mvc extension, such as product.mvc/search/1, it works. But none of my links of course contain the .mvc extension, and I do not believe that they should. Thus clicking a link in my application gets a "Page cannot be found" error.

    Should I see the url get changed by IIS to include this extension? I currently do not. How can I tell if IIS is using the correct route rules?

    taq

     

    Perhaps a better way of asking this: Should all of my urls and redirects include the .mvc extension explicitly? Example: Response.Redirect("Product.mvc/Search/1")

     

  • Re: URL Routing in IIS 5.1

    02-19-2008, 2:37 PM
    Answer

    I'm not sure what you mean by "all the other hackery needed for IIS 5.1". Creating a new MVC application from scratch here's what I did to get it working on IIS 5.1 (you'll need to do the same for IIS 6 too if you don't use wildcard mapping, BTW):

    1. Change the first route in Global.asax.cs to include .mvc
    2. Configure the Web Project to use IIS
    • Your Web Project, Properties, Web, Servers, Use IIS Server
    • Click the button to Create Virtual Directory automatically
    3. Open IIS management program from Administrative Tools
    • Your Virtual Directory (created in Step 2 above), Properties
      • Under the Virtual Directory tab -- Configuration, Mappings, create mapping for .mvc extension
      • Under the Documents tab -- Delete all documents in the list, Add Default.aspx

    4. Run your project from inside VS and it should work. (It'll ask if you want to change web.config to enable debugging.)

    The About Us link becomes http://localhost/RoutingTest/Home.mvc/About. (RoutingTest is what I named my project/virtual directory.) All URLs should include the .mvc, unless you have your routing rules set up incorrectly, or you have a URL-Rewriter setup.

    Start a new MVC project from scratch, follow the above, and if you still have problems post again. 

  • Re: URL Routing in IIS 5.1

    02-19-2008, 3:48 PM
    • Member
      141 point Member
    • taq
    • Member since 06-28-2006, 4:17 PM
    • Posts 62

     OK, I think this answers my question. Basically, all URLs in the application have to include the .mvc extension within the URL. Am I correct in assuming the following (using your example):

    To perform a redirect to the About Us page, I would need to do Response.Redirect("/RoutingTest/Home.mvc/About")

    instead of  Response.Redirect("/RoutingTest/Home/About")

    Sort of lessens the appeal of "clean" URLs with MVC. I may need to look into some URL rewriters if this is truly the case.

    taq

  • Re: URL Routing in IIS 5.1

    02-19-2008, 3:52 PM

     Well, you really shouldn't be specifying manual URLs anywhere in your application. You should use the helpers that build URLs based on routes. You just need to know where you want to redirect to within your application, so to say (a controller, an action, etc.), and then let the routing engine build a URL to get there.

    There's a thread on the forums here that talks about an easy URL rewriter that enables the true clean URLs on IIS 5/6. Let me see if I can dig it up. 

    Edit: Here you go. cubanx lays it out about halfway down the page. Haven't tried it yet myself, but this is what I'll use when I get around to it. 

Page 1 of 1 (4 items)