Blocking (Blacklisting) IP Addresses of Comment Spammers in ASP.net

by Chris Friday, July 31 2009

Comment spam is a major annoyance for many blog sites, especially blogs that are "dofollow."

Recently, we have been getting lots of attempted spam comments from places in India and Vietnam. I dug a little deeper, and it appears that these comments all originated from the same two IP addresses.

And us much as I hate to do this, in the interest of reducing comment moderation time, we are now taking up the practice of IP blacklisting.

If this is something you are interested in exploring as an option for your ASP.net blog, I suggest starting with a great article by Mads Kristensen, entitled "Block IP addresses from your website".


Tags: , ,

ASP.net | General

Programmatically Adding the Canonical Tag to Posts in BlogEngine.net

by Chris Tuesday, July 28 2009

On a previous post, I explained how to track bit.ly short URLs on Twitter using Google Analytics through BlogEngine.net (sheesh, what a mouthful).

After doing so, we ran in to the "fun" issue of googlebot crawling and indexing those URLs (ones with the query strings attached). So therefore, we needed a way to add the canonical tag to each page that contained a query string. What we eventually came up with is the following:

 

        string rawUrl = String.Concat(this.GetApplicationUrl(), Request.RawUrl);

if (rawUrl.Contains("/post/"))
{
bool hasQueryStrings = Request.QueryString.Keys.Count > 1;

if (hasQueryStrings)
{
Uri uri = new Uri(rawUrl);
rawUrl = uri.GetLeftPart(UriPartial.Path);

HtmlLink canonical = new HtmlLink();
canonical.Href = rawUrl;
canonical.Attributes["rel"] = "canonical";
Page.Header.Controls.Add(canonical);
}
}

 

It checks if the URL contains "/post/", if true, it checks to see if there are any query strings associated with the URL, if true, it creates the canonical URL and adds the canonical tag to the head of the rendered html page.

However, there is a secondary part to this. The GetApplicationUrl() function was not included, but it basically checks a bunch of variables and concats the full URL.

I posted the full code on the BlogEngine.net Codeplex Discussion Forum. Here is a link to that post.


Tags: , , , ,

ASP.net | Google | Search Engine Optimization (SEO)

How To Use The ReTweet BlogEngine.net Twitter Extension To Track Short URLs With bit.ly and Google Analytics

by Chris Sunday, July 26 2009

If you are using the ReTweet on your BlogEngine.net site, then you may be interested in this.

I recently made another post on our blog regarding an update to the code that allows the use of special characters in the title through URL encoding. You can see that original post here.

This is a second code update that allows one to track the short URL via Google Analytics.


Assuming that you have already installed the Google Analytics tracking code on your site, you can track short URLs by updating the following code of the retweet.cs file.


Line 93: string address = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" + url + System.Web.HttpUtility.UrlEncode("?utm_source=twitter&utm_medium=social-media&utm_term=&utm_content=from-twitter-account&utm_campaign=test-campaign") + "&login=" + bitlyUserName + "&apiKey=" + bitlyApiKey + "&history=" + activateHistory;

 

The emboldened part of the code above is the trick. It URL encodes the necessary tracking parameters in order to prevent from interfering with the bit.ly API. Of course you can change the underlined variables to reflect whatever you want to show up in Google Analytics.


This is super useful for tracking activity through Twitter.

For more information on building tracking URLs for use with Google Analytics, check out their URL Builder.


Tags: , , , , ,

ASP.net | Google

About this Blog

This is a blog about web design and all things that are related to web design. Pertinent and relevant comments and/or questions are highly encouraged, but please be courteous and thoughtful of others whilest making comments.

If you have benefited from a post, please do the right thing and promote it. You can do this by linking to it, tweeting it, or digging it.

Thank you much.

Recent Comments

Comment RSS