views:

40

answers:

1

I'm trying to map the following routes in MVC2.

[absoluteUrl]

[absoluteUrl]/[dynamicBlogName]

These two routes should map to the same controller/actionresult.

e.g PostController/Index

I also need to map these routes.

[absoluteUrl]/post/[dynamicPostName]

[absoluteUrl]/[dynamicBlogName]/post/[dynamicPostName]

These two routes should also map to the same controller/actionresult.

e.g PostController/Default

Any help would be greatly appreciated.

A: 

I'm not in front of Visual Studio - but try something like this.

routes.MapRoute(
      "Default1",                                   
      "",                           
      new { controller = "PostController", action = "Index", dynamicBlogName = ""} 
);
routes.MapRoute(
      "Default2",                                             
      "{dynamicBlogName}",                          
      new { controller = "PostController", action = "Index", dynamicBlogName = ""  } 
);
routes.MapRoute(
      "Default3",                                         
      "post/{dynamicPostName}",                           
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName="" }
);
routes.MapRoute(
      "Default4",                                            
      "{dynamicBlogName}/post/{dynamicPostName}",            
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName=""  }
);
Christopher Stott
Thanks.... I'll give it a go.
James South