开发者

Redirection with a programmatically generated http request in asp.net

开发者 https://www.devze.com 2022-12-29 06:12 出处:网络
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 t

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 = (HttpWebRespo开发者_运维问答nse)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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消