1

I am trying to route 2 pages but its only routing the first registered one only. Here is the code:

 static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("DynamicCity", "{dCity}.aspx", "~/DynamicCity.aspx");
    routes.MapPageRoute("DynamicPage", "{Description}.aspx", "~/DynamicPage.aspx");
}

Why its only routing DynamicCity?

2 Answers 2

1

I am not sure if this will help you because you didn't specify what your URL scheme is. But if all you want is to send /DynamicCity.aspx to the ~/DynamicCity.aspx page and have all of your other pages routed to their own names, you could just do something like this:

static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("Page", "{pageName}.aspx", "~/{pageName}.aspx");
}

But then, since ASP.NET will do this anyway, I am not sure what you are expecting from .NET routing.

Normally, people use MapPageRoute to remove the .aspx extension from the URL (like shown) or to completely change the URL.

static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("Page", "{pageName}", "~/{pageName}.aspx");
}

Have a look at this answer for some other ideas.

Sign up to request clarification or add additional context in comments.

Comments

0

How is the routing system supposed to know the difference between two routes, when both have the same form of {parameter}.aspx? It can't. And since routes are evaluated in order, the first one has priority.

4 Comments

Cant i route 2 different sites?
@Jamil I don't even know what you would mean by "route 2 different sites".
I don't think i had asked much difficult question.
@Jamil Yes, you did. Because like I said in my last comment, I have no idea what you mean by "route 2 different sites". Simply stating it's not a difficult question doesn't explain what you mean. You need to specifically state what you're trying to accomplish.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.