LearnFast.Ninja

Get ref url in ASP.NET C#

This tutorial will show you how to get the information about the URL of the client's previous request that linked to the current URL. In this tutorial you have example of code that detect if the referral URL is from Google paid service. Note that we checking if the UrlReferrer is not null to avoid exception.

Main idea:
Request.UrlReferrer.ToString()

Example:

bool From_Google_Paid;

if (HttpContext.Current.Request.UrlReferrer != null)

{

    if (HttpContext.Current.Request.UrlReferrer.ToString().ToLower().Contains("utm_medium=cpc") == true)

    {

        From_Google_Paid = true;

    }

}


Tags

asp.net

ref urlreferrer request httpcontext utm_medium cpc referral