5

Is there any way to get RouteData from a url string?

I have login form with returlUrl as query string parameter. My routes are defined as : {languageCode}/{controller}/{action}

In action method LogIn(string returlUrl) the returlUrl is something like "en/home/contacts" etc. I need to change languagePart a i dont want to use string.Replace, as routes may change in future.

Thank you.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
Feryt
  • 2,262
  • 2
  • 22
  • 32

2 Answers2

4

So this is an old thread obviously, but for anyone else coming to this question via Google, I just wrote a blog post about a way to do this pretty easily. I actually came across this question on SO when I was attempting to find a way to do this myself but I didn't find one that I liked so I wrote my own.

Creating a RouteData Instance from a URL

Scott
  • 13,735
  • 20
  • 94
  • 152
1

This forums thread might be useful: http://forums.asp.net/t/1281667.aspx

This is the best option I can think of off the top of my head. Bascially, using RouteTable.Routes.GetRouteData and Mocking HttpContextBase based on your Url string.

Jeff Treuting
  • 13,910
  • 8
  • 36
  • 47