this Just in

Home  >>  Blog  >>  Post Detail

Simple Counter Extension fix for BlogEngine.NET 1.5

I was installing the Simple Counter Extension for BlogEngine.Net (created by Al Nyveldt) today when I ran into a slight glitch. My download counts were being tallied properly in the downloadcounts.xml file. However, when I logged in to check my download counts on each link they all said “0”.

That couldn’t be right so I refreshed my cache and still nothing. The problem was that the string in the downloadcounts.xml file was not matching the string from the generated html.

Here are the two strings:

downloadcounts.xml

   1: <files> 
   2:     <file count="1">2009/6/facePLANT.zip</file> 
   3: </files>

Genderated HTML

   1: <a href="/file.axd?file=2009%2f6%2ffacePLANT.zip">

The solution was to add one line code to the SimpleDownloadCounter.cs file. Just open the file and update the UpdateDisplay method:

   1: private string UpdateDisplay(string body)
   2:   {
   3:     if (body.Contains("file.axd?file="))
   4:     {
   5:       int pos = body.IndexOf("file.axd?file=");
   6:       while (pos > 0)
   7:       {
   8:         pos = pos + 14;
   9:         string filename = body.Substring(pos, body.IndexOf("\"", pos) - pos);
  10:         filename = Uri.UnescapeDataString(filename);
  11:         int count = GetFileCount(filename);
  12:         int linkTextEnds = body.IndexOf("</a>", pos);
  13:         body = body.Insert(linkTextEnds, " [Downloads: " + count.ToString() + "]");
  14:         pos = body.IndexOf("file.axd?file=", pos);
  15:       }
  16:     }
  17:     return body;
  18:   }

I added line 10:

   1: filename = Uri.UnescapeDataString(filename);

 

This will remove the URL Encoding from the HTML link before it tries to look it up in the xml file. Now the strings match and the counter works as intended.

comments powered by Disqus

Tags

Archive


Like what you see? Have a question for us? Contact Us.

Call us toll free at 1.888.262.9212