Esempio n. 1
0
 private static string GetShortenedUrl(string pageLinkBack)
 {
     if (!BitlyLogin.IsEmpty() && !BitlyApiKey.IsEmpty())
     {
         string str         = HttpUtility.UrlEncode(pageLinkBack);
         string key         = "Bitly_pageLinkBack_" + BitlyApiKey + "_" + str;
         string webResponse = WebCache.Get(key) as string;
         if (webResponse != null)
         {
             return(webResponse);
         }
         string address = "http://api.bit.ly/v3/shorten?format=txt&longUrl=" + str + "&login="******"&apiKey=" + BitlyApiKey;
         try
         {
             webResponse = GetWebResponse(address);
         }
         catch (WebException)
         {
             return(pageLinkBack);
         }
         if (webResponse != null)
         {
             WebCache.Set(key, webResponse, 20, true);
             return(webResponse);
         }
     }
     return(pageLinkBack);
 }
        private static string GetShortenedUrl(string pageLinkBack)
        {
            if (BitlyLogin.IsEmpty() || BitlyApiKey.IsEmpty())
            {
                return(pageLinkBack);
            }
            string encodedPageLinkBack = HttpUtility.UrlEncode(pageLinkBack);
            string key      = "Bitly_pageLinkBack_" + BitlyApiKey + "_" + encodedPageLinkBack;
            string shortUrl = WebCache.Get(key) as string;

            if (shortUrl != null)
            {
                return(shortUrl);
            }

            string bitlyReq = "http://api.bit.ly/v3/shorten?format=txt&longUrl=" + encodedPageLinkBack + "&login="******"&apiKey=" + BitlyApiKey;

            try {
                shortUrl = GetWebResponse(bitlyReq);
            }
            catch (WebException) {
                return(pageLinkBack);
            }
            if (shortUrl != null)
            {
                WebCache.Set(key, shortUrl);
                return(shortUrl);
            }
            return(pageLinkBack);
        }