Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (43)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)

Main Category  Other
  Website Maintenance (3)
Log In
UserName Or Email:

Password:

Auto-Login:

Hosted by Securewebs.com
 
Home : .NET : ASP.NET : Tracking Referring Domains and URLs to our Website using ASP.NET
 
Read full length articles at Stardeveloper using Twitter Follow on Twitter Facebook Facebook fan page Email Get Articles via Email RSS Get Articles via RSS Feed
Note: This back-end class will also be the back-end class of referringurls.aspx ASP.NET page. Thus both referringdomains.aspx and referringurls.aspx pages have _ReferringDomainsAndURLs as their back-end class. We do that because this back-end class does nothing more than setting a few properties of the web components placed on the respective ASP.NET pages.
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _ReferringDomainsAndURLs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
	SqlDataSource2.SelectParameters["ForYear"].DefaultValue =
		DateTime.Now.Year.ToString();

	SqlDataSource3.SelectParameters["ForYear"].DefaultValue =
		DateTime.Now.Year.ToString();
	SqlDataSource3.SelectParameters["ForMonth"].DefaultValue =
		DateTime.Now.Month.ToString();

	SqlDataSource4.SelectParameters["ForYear"].DefaultValue =
		DateTime.Now.Year.ToString();
	SqlDataSource4.SelectParameters["ForMonth"].DefaultValue =
		DateTime.Now.Month.ToString();

	SqlDataSource5.SelectParameters["ForYear"].DefaultValue =
		DateTime.Now.Year.ToString();
	SqlDataSource5.SelectParameters["ForMonth"].DefaultValue =
		DateTime.Now.Month.ToString();
	SqlDataSource5.SelectParameters["ForDay"].DefaultValue =
		DateTime.Now.Day.ToString();

	if (Request.QueryString["forYear"] == null)
	{
		YearLabel1.Text = DateTime.Now.Year.ToString();
		YearLabel2.Text = YearLabel1.Text;
		YearLabel3.Text = YearLabel1.Text;
		YearLabel4.Text = YearLabel1.Text;
	}
	else
	{
		YearLabel1.Text = Request.QueryString["forYear"];
		YearLabel2.Text = YearLabel1.Text;
		YearLabel3.Text = YearLabel1.Text;
		YearLabel4.Text = YearLabel1.Text;
	}

	if (Request.QueryString["forMonth"] == null)
	{
		MonthLabel1.Text = DateTime.Now.Month.ToString();
		MonthLabel2.Text = MonthLabel1.Text;
		MonthLabel3.Text = MonthLabel1.Text;
	}
	else
	{
		MonthLabel1.Text = Request.QueryString["forMonth"];
		MonthLabel2.Text = MonthLabel1.Text;
		MonthLabel3.Text = MonthLabel1.Text;
	}

	if (Request.QueryString["forDay"] == null)
		DayLabel1.Text = DateTime.Now.Day.ToString();
	else
		DayLabel1.Text = Request.QueryString["forDay"];

	DateTimeLabel.Text = DateTime.Now.AddHours(
		Convert.ToInt32(
			ConfigurationManager.AppSettings[
				"SD_Tut_TimeOffset"])).ToString();
    }
}

Explanation
If year, month, and day values are not given in the query string for this page, we set the year, month and day values of all the components within the ASP.NET page to the current year, month and day. Lastly, we set the date and time label to be displayed at the top of the report under the title of the website, after adding time zone offset to it.

referringurls.aspx
Let us now quickly create the last ASP.NET page which will display it's own set of reports. Open Notepad and create a new text file. Copy the following code and then paste it in the Notepad. Now save this text file as "referringurls.aspx" in the same folder where you are keeping the other ASP.NET pages for this application.

<%@ Page Language="C#" AutoEventWireup="true"
	CodeFile="referringdomainsandurls.aspx.cs" EnableViewState="false"
	Inherits="_ReferringDomainsAndURLs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Tracker Referring URLs Report</title>
    <style>
		body { font-family:Verdana; font-size:85%; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    
	<a href="report.aspx">
		<b style="font-size:large"><asp:Label ID="HeaderLabel"
			Text="<%$ AppSettings:SD_Tut_WebSiteName %>"
			runat="server" /> Tracker Report</b></a><br />
			(DateTimeAfterOffset: <asp:Label ID="DateTimeLabel"
				runat="server" />)
	<br /><br />
		
	<div align="center"><a href="report.aspx">Main Page</a> 
		· <a href="referringdomains.aspx">Referring Domains</a> 
		· Referring URLs</div>
	<br />
    
	<asp:SqlDataSource ID="SqlDataSource1"
		SelectCommand="SD_Tut_GetYearlyReportForReferringURLs"
		SelectCommandType="StoredProcedure"
		ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
		runat="server"></asp:SqlDataSource>

	<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
		AutoGenerateColumns="false" Width="700"
		runat="server">
		<HeaderStyle BackColor="Beige" />
		<Columns>
			<asp:HyperLinkField HeaderText="Year"
				DataNavigateUrlFields="Year"
		DataNavigateUrlFormatString="referringurls.aspx?forYear={0}"
				DataTextField="Year" />
			<asp:BoundField HeaderText="No. of Referring URLs"
				DataField="NoOfReferringURLs" />
			<asp:BoundField HeaderText="Referrers"
				DataField="Referrers" />
		</Columns>
	</asp:GridView><br />

	<asp:SqlDataSource ID="SqlDataSource2"
		SelectCommand="SD_Tut_GetMonthlyReportForReferringURLs"
		SelectCommandType="StoredProcedure"
		ConnectionString="<%$ ConnectionStrings:SD_Tut_TrackerDB %>"
		runat="server">
		<SelectParameters>
			<asp:QueryStringParameter
				Name="ForYear" QueryStringField="forYear"
				Type="Int32" />
		</SelectParameters>
	</asp:SqlDataSource>
		
	Referring URLs in the year: <b><asp:Label ID="YearLabel1"
		runat="server" /></b><br /><br />
		
	<asp:GridView ID="GridView2" DataSourceID="SqlDataSource2"
		AutoGenerateColumns="false" Width="700" runat="server">
		<HeaderStyle BackColor="Beige" />
		<Columns>
			<asp:HyperLinkField HeaderText="Month"
				DataNavigateUrlFields="Year,Month"
				DataNavigateUrlFormatString=
	"referringurls.aspx?forYear={0}&forMonth={1}#detailedMonthlyReport"
				DataTextField="Month" />
			<asp:BoundField HeaderText="No. of Referring URLs"
				DataField="NoOfReferringURLs" />
			<asp:BoundField HeaderText="Referrers"
				DataField="Referrers" />
		</Columns>
	</asp:GridView><br />

Previous ( 12 Gone )( 2 Remaining ) Next

Comments/Questions ( Threads: 4, Comments: 8 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. trying to follow instruction but ran into this error which I tried to gogle out to no avail
  2. How to track Users visit time and Page Viewstime on web pages ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.
  3. Maybe I am dumb ( 1 Reply )
  4. Great tutorials ( 2 Replies ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.