Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top