aventic
aventic

Reputation: 1514

url routing webforms conflict

Im just getting into Global.asax and the way to do url routing in WebForms. Here Im having a bit of a conflict with my default.aspx and my other files.

I want all my files to have the friendly url ie. mysite.com/welcome/ etc and Im achieving this by doing:

routes.MapPageRoute("root_pages", "{file}/{*action}", "~/{file}.aspx");

by this I can write mysite.com/welcome.aspx into mysite.com/welcome/ and have a default action if I want. But then my conflict occurs between my default routing:

routes.MapPageRoute("default", "{*action}", "~/default.aspx");

I also want to access some action on my default.aspx - but it seems I cant when Im doing it like this?

It will pick the file line and go with that, so I cant do mysite.com/logout/ which is a function on my default.aspx page, it will ofcouse look for a file in this case.. Is there any other way to do what I want? So I can use both routes?

Hope you can help me out

Kind regards

Upvotes: 0

Views: 193

Answers (1)

Munjal Pandya
Munjal Pandya

Reputation: 115

It will always take the first route and go with it. In your case, it will look for logout.aspx which doesn't exist. The only option is to use the URL mysite.com/default/logout.

We can consider this as a limitation of URL Routing in WebForms.

You can check my blog series for URL Routing in Web forms at following URL.

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

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

There are more articles in this series.

Upvotes: 1

Related Questions