I would like the server to call a URL (an ashx page) programmatically and store the response as a string. Using HttpWebRequest doesn't seem like it will work properly because I do not want to redirect the client there.
Thanks.
I would like the server to call a URL (an ashx page) programmatically and store the response as a string. Using HttpWebRequest doesn't seem like it will work properly because I do not want to redirect the client there.
Thanks.
First, you need to define what you mean by "call":
Should the user's browser navigate to a specific URL? use Response.Redirect()
Should the output of your ASP.Net page include the contents of another URL? Use an iframe
Do you want your code to retrieve the contents of another URL and process it? Use WebRequest.Create(), but be aware that the request is issues by the IIS user by default.
I thought HttpWebRequest was the "easy" way, though. What's so bad about it?
Inside the ashx you should use Response.Redirect:
System.Web.HttpContext.Current.Response.Redirect("http://www.stackoverflow.com/");
or:
System.Web.HttpContext.Current.Server.Transfer("a path to a page on the same server");
At your page you can do a: