Detecting HTTP redirect

Posted on 2009-04-01
Last Modified: 2013-12-17

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
I want to store this in variables so that I know where does the URL redirects to.

I  need sample code in c#


Question by:zaki100
1 Comment
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 24044081
The following should do what you need:
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    string finalUri = resp.ResponseUri.ToString();

Open in new window


Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question