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:
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); }
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
);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.