views:

53

answers:

3

I have an asp.net-mvc app with the following aspx pages served by my 'Users' controller: Index.aspx, User.aspx, UsersIntoActivity.aspx and UsersUsingLocation.aspx.

In my Global.ashx.cs I've got the following routes set up:

routes.MapRoute(
            "UsersHome",
            "Users",
            new { controller = "Users", action = "Index" });

routes.MapRoute(
            "Users",
            "Users/{id}/{name}",
            new { controller = "Users", action = "User", id = "", name = "" });

routes.MapRoute(
            "UsersUsing",
            "Users/Using/{locationId}/{name}",
            new { controller = "Users", action = "UsersUsingLocation", locationId = "", name = "" });

routes.MapRoute(
            "UsersInto",
            "Users/Into/{activityId}/{name}",
            new { controller = "Users", action = "UsersIntoActivity", activityId = "", name = "" });

The problem is that when I try to access UsersIntoActivity.aspx or UsersUsingLocation.aspx via the urls 'website/Users/Into/1/some-activity' or website/Users/Using/1/some-location the appropriate ActionResult method is being invoked, but the User method also gets invoked afterwards.

+2  A: 

I would imagine a second request to that route is coming from the browser for some reason. Try capturing the traffic between the browser and the web server using Fiddler2. This can help you rule-out the possibility that a 301/302 redirect is occurring or references to other resources exist in the rendered HTML (such as in an image, script, or link tag).

gWiz
Ah funny you should mention images or other resources, as when the User(id, name) method is invoked, the arguments are something like "Images" and "MySiteLogo.png" which is rather strange.
mdresser
David Liddle's response should sort that out.
gWiz
See also this article: http://blog.codeville.net/2008/07/07/overriding-iis6-wildcard-maps-on-individual-directories/
gWiz
One more thing, is there a way to get Fiddler to capture traffic when debugging my site from Visual Studio?
mdresser
+1  A: 

Consider using route debugger to check your routes:

http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

That should give you answer, what is really called.

LukLed
+2  A: 

Following on from gWiz's reply, as a general rule after applying the mapping extension in IIS (for IIS 5 and 6), I then right click the properties of image and/or script FOLDERS and then remove the aspnet_isapi extension you just added. MVC routes will now not be called for file requests in these folders.

Alternatively setup an ignore route extension in your global asax.

this.Routes.IgnoreRoute("Content/{*pathInfo}");
//e.g if your images, css, scripts are in a content folder
David Liddle