1

I have a Global.asax where I define routes (see RegisterRoutes method below)

I will have a lot of routes, so I would like keep this method in a separate static class, importing using a namespace in the Global Asax and use the method in the Application_Start.

Unfortunately I'm not able to do it.

So my question:

  • Can I use static class in Global.asax?
  • If yes, how can I do it?

    void RegisterRoutes(RouteCollection routes) { // Register a route for Categories/All routes.MapPageRoute( "All Categories", // Route name "Categories/All", // Route URL "~/AllCategories.aspx" // Web page to handle route ); // Register a route for Products/{ProductName} routes.MapPageRoute( "View Content", // Route name "Content/{ContentId}", // Route URL "~/Cms/FrontEndCms/Content.aspx" // Web page to handle route ); } protected void Application_Start(object sender, EventArgs e) { // ROUTING. RegisterRoutes(RouteTable.Routes); } 
1
  • Thanks Nathan Koop for your corrections :) Commented Aug 4, 2011 at 15:43

1 Answer 1

3

You should definitely be able to do this:

 protected void Application_Start(object sender, EventArgs e) { // ROUTING. Helper.RegisterRoutes(RouteTable.Routes); } public static class Helper { public static void RegisterRoutes(RouteCollection routes) { // Register a route for Categories/All routes.MapPageRoute( "All Categories", // Route name "Categories/All", // Route URL "~/AllCategories.aspx" // Web page to handle route ); // Register a route for Products/{ProductName} routes.MapPageRoute( "View Content", // Route name "Content/{ContentId}", // Route URL "~/Cms/FrontEndCms/Content.aspx" // Web page to handle route ); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.