URL Tracking
In this article you will see how simple it is to Track the stations from end user to Destinations.
Here we will see how What is 302 status code. and how our browser IE or Mozill firefox
treat it
Merchants of the web site promotes Campaigns , offers to differnet different
agencies in the format of URL.
e.g. Merchant A created campaing fox XYZ product and published to Agenciy A
Agency A wrapped this url and published to Publisher A publisher C etc.
Now Merchant will receive referr as Agency A. he will not get any Idea about Publisher
C.
Agency A will get traffic from Publishers A , B, C
Now some how Merchant A got end user link and he want to track how many publishers
are comong in.
Below is the self explanetory code
Create one web page add Button control Textbox in it and take any url from any web
site where you will get redirected.
public
partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string TrackUrl(string url)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method =
"Head"; // Call method head so that only header you will get in response not the entire page
req.AllowAutoRedirect =
false;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
if (response.StatusCode == HttpStatusCode.Redirect) // Check if status code is 302
{
WebHeaderCollection c = (WebHeaderCollection)response.Headers;
response.Close();
return c["Location"];
}
return "";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string url = txtUrl.Text;
int i = 1;
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
while (true)
{
url = TrackUrl(url);
if (url == "")
break;
i++;
Response.Write(
"Location " + i.ToString()+ ":" + url+ "<BR />");
}
//Response.End();
}
}
Conclusion: Whenever your site is redircting the user to different location your broser gets
302 as status code and Redirected URL in Header
By Sat Sat Popularity (1305 Views)