Search For

Get Referrer URL

Flag Hide Line Nos
Flagging a Snippet, takes the snippet to Moderator Attention;


0
C# Program to find the visitor referrer URL, it can be used in ASP.NET or RAZOR to find the source location of the user.
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Web;
using System.Text.RegularExpressions;
 
namespace forgetcode
{
    class Program
    {
        static void Main(string[] args)
        {
           
             Uri referrer = HttpContext.Current.Request.UrlReferrer;
            if (referrer != null)
            {
                string original = referrer.OriginalString.ToLower();
                Console.WriteLine("Visitor Came From "+original);
            }
        }
       
     }
}
Vote! You feel this code is working like charm ? Go a head Login and Press up arrow.
Didn't work ?, press down arrow and let us know the error in comments

Comments

  • stevemannar
    You can retrieve exact url using URI Uri myUri = new Uri("http://forums.asp.net/t/1110512.aspx?"); string host = myUri.Host; full source http://net-informations.com/faq/asp/domain.htm steve
  • We donno you ! Login or Signup to make a Comment