Introduction
This article explains how to find the Google Page Rank of specific webpages in ASP.Net. Page Rank is an internal metric Google maintains that indicates how popular Google thinks a web page is. The value is calculated by how many websites link to that page, and how popular those websites are. The minimum value of page rank is 0 and the maximum value is 10.
While Page Rank is an internal metric that is being recalculated all the time, Google also maintains a public Page Rank, that is updated from the internal Page Rank several times a year. There are several websites available that can you use to find web page rank, you can also use the Google toolbar to find the page rank but here we are going to find the page rank of the web page programmatically.
Step 1
Open Visual Studio and start to create a website.
Step 2
In the "Dafault.aspx" page add the following controls.
- <form id="form1" runat="server">
- <div>
- <asp:Label ID="Label1" runat="server" Text="Enter your url"
- style="top: 371px; left: 508px; position: absolute; height: 19px; width: 82px">
- </asp:Label><asp:TextBox ID="UrlText" runat="server"
- style="top: 366px; left: 609px; position: absolute; height: 23px; width: 208px">
- </asp:TextBox>
- </div>
- <p> </p>
- <p>
- <asp:Button ID="FindPageRankBtn" runat="server" Text="FindRank"
- onclick="FindPageRankBtn_Click"
- style="top: 362px; left: 842px; position: absolute; height: 26px; width: 83px" />
- </p>
- <asp:Label ID="ShowRank" runat="server"
- style="top: 431px; left: 612px; position: absolute; height: 19px; width: 300px"
- ForeColor="#FF3300" Font-Bold="True"></asp:Label>
- </form>
Step 3
In "Default.aspx.cs" add the following namespace.
- using System.Net;
- using System.IO;
- using System.Text.RegularExpressions;
Step 4
Here is the complete "Default.aspx.cs" page.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Net;
- using System.IO;
- using System.Text.RegularExpressions;
- public partial class GooglePageRenk : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void FindPageRankBtn_Click(object sender, EventArgs e)
- {
- GooglePR Gpr = new GooglePR();
- string Myurl = UrlText.Text;
- int googlePageRank = Gpr.MyPageRank(Myurl);
- ShowRank.Text =" Google page rank is: :-" + googlePageRank.ToString();
- }
- public class GooglePR
- {
- public GooglePR()
- {
- }
- private const UInt32 myConst = 0xE6359A60;
- private static void Hashing(ref UInt32 a, ref UInt32 b, ref UInt32 c)
- {
- a -= b; a -= c; a ^= c >> 13;
- b -= c; b -= a; b ^= a << 8;
- c -= a; c -= b; c ^= b >> 13;
- a -= b; a -= c; a ^= c >> 12;
- b -= c; b -= a; b ^= a << 16;
- c -= a; c -= b; c ^= b >> 5;
- a -= b; a -= c; a ^= c >> 3;
- b -= c; b -= a; b ^= a << 10;
- c -= a; c -= b; c ^= b >> 15;
- }
- public static string PerfectHash(string theURL)
- {
- string url = string.Format("info:{0}", theURL);
- int length = url.Length;
- UInt32 a, b;
- UInt32 c = myConst;
- int k = 0;
- int len = length;
- a = b = 0x9E3779B9;
- while (len >= 12)
- {
- a += (UInt32)(url[k + 0] + (url[k + 1] << 8) +
- (url[k + 2] << 16) + (url[k + 3] << 24));
- b += (UInt32)(url[k + 4] + (url[k + 5] << 8) +
- (url[k + 6] << 16) + (url[k + 7] << 24));
- c += (UInt32)(url[k + 8] + (url[k + 9] << 8) +
- (url[k + 10] << 16) + (url[k + 11] << 24));
- Hashing(ref a, ref b, ref c);
- k += 12;
- len -= 12;
- }
- c += (UInt32)length;
- switch (len)
- {
- case 11:
- c += (UInt32)(url[k + 10] << 24);
- goto case 10;
- case 10:
- c += (UInt32)(url[k + 9] << 16);
- goto case 9;
- case 9:
- c += (UInt32)(url[k + 8] << 8);
- goto case 8;
- case 8:
- b += (UInt32)(url[k + 7] << 24);
- goto case 7;
- case 7:
- b += (UInt32)(url[k + 6] << 16);
- goto case 6;
- case 6:
- b += (UInt32)(url[k + 5] << 8);
- goto case 5;
- case 5:
- b += (UInt32)(url[k + 4]);
- goto case 4;
- case 4:
- a += (UInt32)(url[k + 3] << 24);
- goto case 3;
- case 3:
- a += (UInt32)(url[k + 2] << 16);
- goto case 2;
- case 2:
- a += (UInt32)(url[k + 1] << 8);
- goto case 1;
- case 1:
- a += (UInt32)(url[k + 0]);
- break;
- default:
- break;
- }
- Hashing(ref a, ref b, ref c);
- return string.Format("6{0}", c);
- }
- public int MyPageRank(string MyUrl)
- {
- string HashDomain = PerfectHash(MyUrl);
- string RequestedURL = string.Format("http://toolbarqueries.google.com/" +
- "tbr?client=navclient-auto&ch={0}&features=Rank&q=info:{1}",
- HashDomain, MyUrl);
- try
- {
- HttpWebRequest HttpRequest = (HttpWebRequest)WebRequest.Create(RequestedURL);
- string GetResponse = new StreamReader(
- HttpRequest.GetResponse().GetResponseStream()).ReadToEnd();
- if (GetResponse.Length == 0)
- return 0;
- else
- return int.Parse(Regex.Match(GetResponse,
- "Rank_1:[0-9]:([0-9]+)").Groups[1].Value);
- }
- catch (Exception)
- {
- return -1;
- }
- }
- }
- }
Step 5
Now run the website and type any URL in TextBox then click on "FindRank".


Manav PandyaPosted Sep 28, 2016, 12:42 PM
Can i get source code pls ..
Santhakumar MunuswamyPosted Apr 25, 2015, 7:18 AM
Good work
Gowtham RajamanickamPosted Apr 25, 2015, 6:42 AM
good
Gowtham RajamanickamPosted Apr 25, 2015, 6:41 AM
good
Valette ClarkPosted Apr 1, 2015, 11:23 PM
Thanks for sharing http://drilldriversq.com/
MikeJones PingPosted Jun 12, 2014, 8:27 PM
Thanks for share. I use code inhttp://www.kythuatmang.net/google-pagerank-checker.php
Sandeep SharmaPosted May 14, 2014, 12:06 PM
Special thanks for commenters particularly for knowing the differences in between " :- " and " : "
Sam HobbsPosted May 12, 2013, 10:19 AM
Now I understand. Authors often use ":-" instead of ":". That however is incorrect; it should just be ":". I think however that if there had been a space between "-" and "5" then I would have understood.
Suthish NairPosted Apr 24, 2013, 10:37 AM
Hi Prabhakar, The image in this article is a little confusing. There is no problems in your article and it's a good one... Sam is the editor of this article, he have no option to change the original image. So he pointed out here in comments, so you can correct it.
Prabhakar MauryaeditedPosted Apr 22, 2013, 6:17 AMEdited Apr 22, 2013, 6:29 AM
Hi Sam Actually I am not showing (-5) rank of "c-sharocorner" in my article. I try to its more attractive with the help of some symbol like (":-"), and when I declare like ( :-5), so its seems like minus(-5), so it may be confusing as -5, but I also wrote in my article, "The minimum value of page rank is 0 and the maximum value is 10." So it is not possible rank become to -5. Thanks
Suthish NairPosted Apr 22, 2013, 5:30 AM
good catch, Sam :)
Sivaraman DhamodaranPosted Apr 22, 2013, 12:40 AM
1) Step 2: Says Add the following controls. [Provide a screen shot] That will help the beginners what controls to be added 2) Explain the code, this should be kind of what it os doing.. - Thanks for the share.. It is useful.. Only concern is that it will not reach all the audienece if you just place the code
Sam HobbsPosted Apr 21, 2013, 3:43 PM
In case anyone wants to know, the page rank for c-sharpcorner.com is 5, not -5. The image in this article is a little confusing.