1

I am Using ASP.NET web forms. In my application i need to be able to get to routedata of UserName in URL.

Url looks like this: localhost/profile/MyRAndomUserNAme

There are no problems to receive it in On_Load event like this:

string userName = Page.RouteData.Values["UserName"] as string;

But if i am in my Asmx WebService and try to receive UserName from URL, it just doesn't work. So how do i get around it?

PS: Its not a MVC project so i cant use var userName = ViewContext.RouteData.Values["UserName"]; on a view

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Timsen
  • 4,066
  • 10
  • 59
  • 117

1 Answers1

1

I have not done asp.net non-MVC for a while but I believe this is possible using the Current property of the HttpContext class. The Current property is static and should be always available during a web page post back.

Use HttpContext.Current.Request.QueryString["UserName"] to get the values you require.

Kami
  • 19,134
  • 4
  • 51
  • 63
  • 1
    See the answer by 'Scott Anderson' at http://stackoverflow.com/questions/298219/getting-to-the-query-string-get-request-array-inside-a-web-service-in-net. You will need to update the web config to allow `GET` strings to be passed to your web service. – Kami Nov 19 '12 at 10:37