Solved

Detecting HTTP redirect

Posted on 2009-04-01
1
291 Views
Last Modified: 2013-12-17
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
Comment
Question by:zaki100
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 24044081
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), 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, f…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), 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…

679 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