wcsf and asp.net routing

Topics: User Forum
Jun 2, 2009 at 12:30 PM

I am trying to use ASP.NET routing in my WCSF application. I first created a custom webclientapplication file so that on application start I can register the routes.

public class CustomWebClientApplication : WebClientApplication
  protected override void Application_Start(object sender, EventArgs e)
    base.Application_Start(sender, e);
  }<font size="2">




  private void RegisterRoutes(RouteCollection Routes)
    Route r = new Route("{Parameter}", new MEOSimpleRouteHandler());

During debugging i found that the RegisterRoutes function is being called properly. Unfortunatly its not working. (in an normal web application it works great).

Any body have a clue why its not working?

Jun 2, 2009 at 7:33 PM

Hi oversight,


                I managed to use ASP.NET routing in a WCSF application, but found no errors. Below you can find some questions that might help us reproduce and solve the problem:

1.       What is the error / exception you are receiving?

2.       How are you implementing the MEOSimpleRouteHandler?

3.       Are you using a Web Site or a WAP Web Client Solution?

4.       Is the MEOSimpleRouteHandler.GetHttpHandler method executing (you can verify this with a breakpoint in the method)


Below are the steps I performed to reproduce the scenario (similar but without a custom WebClientApplication):

1.       I started with the modularity quickstart

2.       Add the following lines to the web.config:


  <add name="UrlRoutingModule"







3.       Deleted the global.asax file

4.       Added a new global.asax file with the Add Wizard (it creates the c# file)

5.       Make the Global class inherit from Microsoft.Practices.CompositeWeb.WebClientApplication (instead of System.Web.HttpApplication)
               public class Global : Microsoft.Practices.CompositeWeb.WebClientApplication

6.       Add the following code to this class (this routes every .aspx to /routed/WebForm1.aspx):


protected override void Application_Start(object sender, EventArgs e)


            base.Application_Start(sender, e);




        public static void RegisterRoutes(RouteCollection routes)


            Route route = new Route("{parameter}", new MyRouteHandler());




        public class MyRouteHandler : IRouteHandler


            public IHttpHandler GetHttpHandler(RequestContext requestContext)


                string pageName = requestContext.RouteData.GetRequiredString("Parameter");

                if (pageName.EndsWith("aspx"))


                    pageName = pageName.ToLower() == "home" ? "default" : pageName;

                    string virtualPath = string.Format("~/routed/WebForm1.aspx", pageName);

                    return (Page)BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page));



                return requestContext.HttpContext.Handler;




Hope it helps!


Matias Bonaventura


Jun 30, 2009 at 1:41 PM

Hi Matias,

Thanks for posting that. It works for me when routing within the same project, however I have another problem: My WCSF solution is created using the WAP option, so each module has its own project in the Websites folder.

If I add a route to Global.asax that maps within the Shell module such as "Home.aspx" to map to "~/Default.aspx" the URL works successfully. If I add a route to the Global.asax that points to another module such as "Home.aspx/Contacts" to map to "~/Contacts/Default.aspx", I get the error "System.ArgumentException: Invalid type owner for DynamicMethod" when accessing that URL. Am I missing something here?

I am also looking for some pointers on how to best implement adding routes for each module in the WAP scenario. Ideally, I would like each module to add its own routes when it is deployed so that the Shell module does not know anything about routes for the other modules. What do you think would be the best approach here?