Googles analytic url ?gclid= causes error

Topics: ASP.NET 2.0
Jul 20, 2011 at 6:47 AM
Edited Jul 20, 2011 at 6:51 AM


When analytics is turned on adwords, google adds a variable to the url, for example:

This is causing an error on the homepage:



Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

Line 193:            var currentPage = PageIndex();
Line 194:
Line 195:            var visiblePosts = this.Posts.FindAll(p => p.IsVisible);
Line 196:            var postCnt = visiblePosts.Count;
Line 197:

Source File: d:\home\Default\\BlogEngine.Web\App_Code\Controls\PostPager.cs    Line: 195 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   App_Code.Controls.PostPager.PagerTag() in d:\home\Default\\BlogEngine.Web\App_Code\Controls\PostPager.cs:195
   App_Code.Controls.PostPager.Render(HtmlTextWriter writer) in d:\home\Default\\BlogEngine.Web\App_Code\Controls\PostPager.cs:43
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25


Can someone tell me the best work around (the client needs analytics so i can't turn it off) - i'm using BlogEngine.NET


Jul 22, 2011 at 10:19 PM

anyone any ideas?

thanks in advance

Jul 27, 2011 at 10:22 AM

This was a bug in the post page control that was fixed at one point.

A good version of this file is here.  It's PostPager.cs file in the App_Code\Controls folder that needs to be updated.  There's actually only one change which is to add the following highlighted line at around line 186.

private string PagerTag()
	if (this.Posts == null) return "";
        ..... existing code ......

This should get past the error.  But you probably also need to modify default.aspx.cs in the root folder.  On or around line 44 is the following.  You would want to add the part highlighted in yellow ... this would allow the gclid query string parameter (intentional line breaks added):

else if (
 Request.QueryString.Count == 0 ||
 !string.IsNullOrEmpty(Request.QueryString["page"]) ||
 !string.IsNullOrEmpty(Request.QueryString["theme"]) ||
 !string.IsNullOrEmpty(Request.QueryString["blog"]) ||