Tuesday, April 30, 2013

Count GetAlexa Rank

Count GetAlexa Rank

Storing  Alexa value in viewstate and using that viestate as per requirement.

private int GetAlexaRank(string domain)
    {
        var alexaRank = 0;
        try
        {
            var url = string.Format("http://data.alexa.com/data?cli=10&dat=snbamz&url={0}", domain);
            var doc = XDocument.Load(url);
            var rank = doc.Descendants("POPULARITY")
            .Select(node => node.Attribute("TEXT").Value)
            .FirstOrDefault();

            if (!int.TryParse(rank, out alexaRank))
                alexaRank = -1;

        }
        catch (Exception e)
        {
            return -1;
        }
        ViewState["alaska"] = Convert.ToString(alexaRank);
        return alexaRank;

    }

No comments:

Post a Comment