Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Detecting HTTP redirect

Hello,

How can I request a web site and detect if it redirects to another url?
for example i want to put the url in a textbox if the url return redirect then I get something like:

HTTP/1.1 302 Found
Location: http://redirected.com
I want to store this in variables so that I know where does the URL redirects to.

I  need sample code in asp.net c#

Thanks

Zaki
0
zaki100
Asked:
zaki100
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
The following should do what you need:
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.hotmail.com");
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
 
    string finalUri = resp.ResponseUri.ToString();
    resp.Close();

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now