0

I have a route config file that I'm trying to route all URLs that follow the formula .com/{a page}/{a subpage}, to route to a specific page .com/Default/Page.aspx. My problem is that it does this for all the pages (i.e., .com/Account/Login.aspx. Is there a way to specify that I want it to route to that page only when a user types it into the address bar, possible only when they leave out the .aspx extension? This is what I have so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.Membership.OpenAuth;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;

namespace CouponsForGiving
{
    public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.Ignore("{resource}.axd/{*pathInfo}");
            routes.MapPageRoute("LearnMore", "LearnMore", "~/LearnMore.aspx");
            routes.MapPageRoute("DefaultPage", "{nponame}", "~/Default/NPOPage.aspx");
            routes.MapPageRoute("CampaignPage", "{nponame}/{campaignname}", "~/Default/CampaignPage.aspx"); //This one routes a lot of other pages
            routes.EnableFriendlyUrls();
        }
    }
}

Thanks!

Jack
  • 950
  • 2
  • 17
  • 36

1 Answers1

0

Issue here is with the overriding of a route. If there are 2 routes with same number of parameters and if there is no hard-coded value, it will always consider the first route, which is declared. For Example, if following 2 routes are registered,

routeCollection.MapPageRoute("LearnMore", "{param1}/{param2}", "~/About.aspx");
routeCollection.MapPageRoute("DefaultPage", "{param3}/{param4}", "~/Account/Login.aspx");

In the above case, the route LearnMore will only be consider as valid which will be requesting About.aspx page.

You can do something like below:

routeCollection.MapPageRoute("LearnMore", "learnmore/{param1}/{param2}", "~/About.aspx");
routeCollection.MapPageRoute("DefaultPage", "default/{param3}/{param4}", "~/Account/Login.aspx");

This will redirect to the respective pages. You can go through below URL for more details on URL Routing.

http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-part-2.html

Thanks & Regards, Munjal