Hemanta
Hemanta

Reputation: 11

Need Help in converting Classic ASP Code to ASP.NET code

Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://www.indexguy.com/request_server.cfm?member_id=15893&id="+request.querystring("id")+"&"+request.querystring, False
xml.Send

How can I build the querystring parameter to a string object in C#/VB.NET

"member_id=15893&id="+request.querystring("id")+"&"+request.querystring"

Upvotes: 1

Views: 104

Answers (3)

Grant Thomas
Grant Thomas

Reputation: 45068

In ASP.NET the Page class exposes a Request property which provides access to a QueryString property - this is a NameValueCollection that lets you get values out in much the same way as in your existing example, by specifying keys:

var id = Page.Request.QueryString("id");

var newQuery = string.Format("?member_id=15893&id={0}&", id);

The above can easily be expanded to build more into your required query string.

As for the request you're initiating, that can be achieved using a WebRequest instance; to alter the sample from MSDN only slightly, here is an example:

WebRequest request = WebRequest.Create(yourUrl + newQuery);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();   
Response.Write(response.StatusDescription);

Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader (dataStream);
string responseFromServer = reader.ReadToEnd();
Response.Write(responseFromServer);

reader.Close();
dataStream.Close();
response.Close();

Upvotes: 1

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107606

For ASP.NET, you're going to want to replace the Server.CreateObject("Microsoft.XMLHTTP") with HttpWebRequest.

As for building the query string, that's still identical. You can still retrieve query string parameters by indexing into Request.QueryString. If you're using C# you can keep the + for string concatenation but might be more acceptable to use & in VB.

Upvotes: 1

davecoulter
davecoulter

Reputation: 1826

If you are looking to build a querystring, String.Format("{0}", arg) might be a cleaner method to construct it.

Upvotes: 1

Related Questions