views:

101

answers:

1

Hi everyone, I have a web method in second.aspx,which has to be executed only if the incoming request is 'application/json'.So in my First.aspx page I am programmatically generating a Http request with content type set to 'application/json' using the following code.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/website1/Second.aspx");

        req.ContentType = "application/json";
 HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(resp.GetResponseStream());
            string results = sr.ReadToEnd();
            sr.Close();

and in the Second.aspx i am checking the incoming request in javascript using <%= Request.ContentType %> to see if it is 'application/json'.If yes I want to execute the web method using jquery ajax method.If I write the streamreader 'sr' to a textbox I can see that <%= Request.ContentType %> gives 'application/json'.But my problem is the HTML of Second.aspx is loaded into the textbox on First.aspx but no redirection to Second.aspx is taking place.so I am unable to exceute the web method this way.

Please could someone help me how do I rediret to Second.aspx page with the above programmatically generated HTTP request code?

A: 

You don't. What you are doing is having your application make a web request, read it, and do nothing with it.

Your logic rather convoluted... I don't understand at all why you're doing what you're doing. But if you want to redirect the user to a new page, use Response.Redirect. If you want to execute the page and send the results back to the user use Server.Transfer.

Bryan