Take the 2-minute tour ×

I'm looking to find a way to access the .net query string contained in the standard ASP.NET request object inside a web service. In other words if I set a SOAP web service to this url:


Can I access the ID Get variable?

share|improve this question
add comment

4 Answers

up vote 13 down vote accepted

I just looked for "Request" of the context in asmx file and I saw that. But I'm not sure if it is right.

share|improve this answer
this represents what object? –  AnthonyWJones Nov 18 '08 at 9:28
The webservice class. In this sample it is "Service"; –  Ali Ersöz Nov 18 '08 at 9:35
add comment


share|improve this answer
add comment

Since you ask, I guess there is no HttpContext.Current.Request ?

share|improve this answer
add comment

While searching for the solution of the same problem i decided to take different approach. My query string was packed with lots of variables and since I was not able to access query string data from the web service, and I also did not want to send each query string variable as a separate parameter, I prepared my web method to expect one aditional string parameter.

That parameter was window.location (entire url of the page) in my javascript function on .aspx page

Once I had url in my web service, the rest was quite stright forward

Uri myRef = new Uri(stringMyWindowLocationParameter);
System.Collections.Specialized.NameValueCollection mojQuery = HttpUtility.ParseQueryString(myRef.Query);

Now my query string is contained inside myRef object and this is how I call it

// Instead trying to request query string like this
string myId = HttpContext.Current.Request.QueryString["id"];

// ... I called it like this
string myId = myRef["id"];

Maybe it's not the most elegant way but it solved my problem.

share|improve this answer
add comment

Your Answer


