+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Count for download

Count for download

20 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    05 Nov 2009
    Link to this post
    Hi all,

    Does someone know if there is a way to count the downloads of a file that is stored in a library? Maybe it is already stored somewhere? How can I achieve this?

    Thanks,
    Daniel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Nov 2009
    Link to this post
    Hello Daniel,

    The current implementation does not support this feature out of the box.You need to handle the requests to the content items. Then you can store the data to a custom table in your database. Another control will be bound to this datasource and display needed information. To track the downloads you can create a custom class that inherits from ContentHttpHandler.

    Sample code:

    public class CustomCmsContentHandler : ContentHttpHandler
    {
        public override void ProcessRequest(HttpContext context)
        {
            string path = String.Concat(context.Request.ApplicationPath, "/Libraries/Track/");
            if (context.Request.RawUrl.StartsWith(path, StringComparison.OrdinalIgnoreCase))
            {
                string query = "INSERT INTO track_DocDownloads ([download_date],[Url]) VALUES (GETDATE(),'" + context.Request.RawUrl.ToString() + "')";
                SqlConnection dbconnection = new SqlConnection();
                dbconnection.ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString;
                dbconnection.Open();
                SSqlCommand command = new SqlCommand(query, dbconnection);
                command.CommandType = SCommandType.Text;
                try
                {
                    command.ExecuteNonQuery();
                }
                catch (SqlException ex)
                { }
                finally
                {
                    if (dbconnection != null) command.Dispose();
                }
                dbconnection.Close();
            }
            base.ProcessRequest(context);
        }
    }

    Finally you need to register the HttpHandler in your web.config file.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    05 Nov 2009
    Link to this post
    Hi Mark,

    Thanks for your information.
    I've one question about the registration of this HttpHandler.
    How exactly do I have to register this one?

    I created the class inside the App_Code folder, so I don't know what the namespace should be. Also, I have to give up a VERB and a PATH. Should the path be "*.sflb", or "*.pdf" ?

    -Daniel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Nov 2009
    Link to this post
    Hi Daniel,

    The verb and path depends on the request and type of the request you want to handle. Here is a sample that illustrates how to register the Handler in your web.config file

    <httpHandlers>

    <add verb="*" path="*.pdf" type="CustomCmsContentHandler, App_Code" />

    If you use IIS7 you need to regiser the module under <hanlders> section of -your web.config file

    <add name="CustomCmsContentHandler" path="*.pdf" verb="*" preCondition="integratedMode" type="CustomCmsContentHandler, App_Code" />

    This is a standard ASP.NET handler. You can gather more information at MSDN

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    05 Nov 2009
    Link to this post
    Hi Mark,

    Well, that was how I implemented it.
    The handler isn't working. I'm a bit confused on how to refer to library items.

    I tried the following:

    <add verb="*" path="*.ashx" type="CustomCmsContentHandler, App_Code" />

     

    <add verb="*" path="*.sflb.ashx" type="CustomCmsContentHandler, App_Code" />

    <add verb="*" path="*.sflb" type="CustomCmsContentHandler, App_Code" />

     

    <add verb="*" path="*.sflb" type="CustomCmsContentHandler, App_Code" />

    This is my library on which I want to track for downloads:

    /Libraries/Boek_Concepten/


    This is the code from my handler:
    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using Telerik.Cms.Engine;  
    using System.Data.SqlClient;  
    using System.Configuration;  
     
    /// <summary>  
    /// Summary description for CustomCmsContentHandler  
    /// </summary>  
    public class CustomCmsContentHandler : ContentHttpHandler  
    {  
        public override void ProcessRequest(HttpContext context)  
        {  
            string path = string.Concat(context.Request.ApplicationPath, "/Libraries/Boek_Concepten/");  
            if (context.Request.RawUrl.StartsWith(path, StringComparison.OrdinalIgnoreCase))  
            {  
                string query = "INSERT INTO track_downloads ([DownloadDate], [Url]) VALUES (GETDATE(), '" + context.Request.RawUrl.ToString() + "')";  
                SqlConnection cnn = new SqlConnection();  
                cnn.ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString;  
                cnn.Open();  
     
                SqlCommand cmd = new SqlCommand(query, cnn);  
                cmd.CommandType = System.Data.CommandType.Text;  
     
                try   
                {  
                    cmd.ExecuteNonQuery();  
                }  
                catch (SqlException ex)  
                { }  
                finally 
                {  
                    if (cnn != null) cmd.Dispose();  
                }  
            }  
              
            base.ProcessRequest(context);  
        }  
     
        public CustomCmsContentHandler()  
        {  
              
        }  
    }  
     

    So, what am I doing wrong?

    -Daniel


  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Nov 2009
    Link to this post
    Hello Daniel,

    What do you mean by "The handler isn't working." . Do you have a database with the required tables. Does the handler fails on any row if you attach the code to debugger?

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    05 Nov 2009
    Link to this post
    Yes I have created a new table in the database, but during debug the handler isn't beeing fired? When I debug it isn't doing anything. I just download the file without entering the code of the HttpHandler.

    -Daniel
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Nov 2009
    Link to this post
    Hi Daniel,

    That means the handler is not registered in the right place in your web.config file. Add it to the both section of your web.config file on the first place. It should be fired there. Also this is a sample code.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    05 Nov 2009
    Link to this post
    Okay, thanks. That worked. Didn't know that I had to add it to the handlers of SF itself.

    <

     

    add name="DownloadHandler" verb="*" path="*.sflb.ashx" type="CustomCmsContentHandler, App_Code" />

     


    Only this is working correct in my dev website, but when copying the whole Sitefinity website to my Live server, it does nothing. I build in some Try/Catch blocks, but they don't fire either, so I think it is a problem with these handlers again.

    My Dev version is using the built in webserver from VS2008. Live server is running on IIS6.0.
    Is there another config for this to work?

    -Daniel
  10. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    06 Nov 2009
    Link to this post
    Hi,

    I thought that maybe I have to register the extension '.sflb.ashx' in IIS6? Like you have to do with '.sflb' as in the SF manual.

    Only, IIS6 doesn't allow these extensions.

    Is there any way to do this different?

    -Daniel
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Nov 2009
    Link to this post
    Hi Daniel,

    The .ashx extension should be added by default , so you do not have to add sflb before the dot. Take a look at the attached screenshot.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    06 Nov 2009
    Link to this post
    Well, I have an extension as in your screenshot.
    But the customer handler only responds to: path='*.sflb.ashx'. Other combinations wont work.

    And... when I use the working PATH, it is only working when I use my VS2008 built-in webserver. When I copy my website to the live server, using IIS 6.0, the handler is not being fired?

    -Daniel
  13. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    23 Nov 2009
    Link to this post
    I really hope you can give me some advice on this, because I'm not getting it to work? Thanks! -Daniel-
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Nov 2009
    Link to this post
    Hi Daniel,

    Can you paste the web.config you use the tell us the exact IIS version you use. Also you can share the last version of the code I sent you.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  15. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    25 Nov 2009
    Link to this post
    Hi Ivan,

    Thanks for your reply.
    This is the code of the HttpHandler I use:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using Telerik.Cms.Engine;  
    using System.Data.SqlClient;  
    using System.Configuration;  
     
    /// <summary>  
    /// Summary description for CustomCmsContentHandler  
    /// </summary>  
    public class CustomCmsContentHandler : ContentHttpHandler  
    {  
        public override void ProcessRequest(HttpContext context)  
        {  
            string path = string.Concat(context.Request.ApplicationPath, "/Libraries/Boek_Concepten/");  
            if (context.Request.RawUrl.StartsWith(path, StringComparison.OrdinalIgnoreCase))  
            {  
                string query = "INSERT INTO track_downloads ([DownloadDate], [Url]) VALUES (GETDATE(), '" + context.Request.RawUrl.ToString() + "')";  
                SqlConnection cnn = new SqlConnection();  
                cnn.ConnectionString = ConfigurationManager.ConnectionStrings["Sitefinity"].ConnectionString;  
                cnn.Open();  
     
                SqlCommand cmd = new SqlCommand(query, cnn);  
                cmd.CommandType = System.Data.CommandType.Text;  
     
                try   
                {  
                    cmd.ExecuteNonQuery();  
                }  
                catch (SqlException ex)  
                {  
                    throw ex;  
                }  
                finally 
                {  
                    if (cnn != null) cmd.Dispose();  
                }  
            }  
              
            base.ProcessRequest(context);  
        }  
     
        public CustomCmsContentHandler()  
        {  
              
        }  
    }  
     

    This is the HttpHandler section of my web.config:

    <httpHandlers> 
          <add verb="*" path="*.sflb.ashx" type="CustomCmsContentHandler, App_Code"/>  
          <add verb="*" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.Upload.RadUploadProgressHandler, Telerik.Web.UI"/>  
          <add verb="*" path="*.rss" type="Telerik.Rss.RssHttpHandler, Telerik.Rss"/>  
          <add verb="*" path="*.rss.ashx" type="Telerik.Rss.RssHttpHandler, Telerik.Rss"/>  
          <add verb="GET" path="*.sflb" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add verb="GET" path="*.sflb.ashx" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add verb="GET" path="*.tmb" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add verb="GET" path="*.tmb.ashx" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add verb="*" validate="false" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI"/>  
          <add verb="*" validate="false" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler, Telerik.Web.UI"/>  
          <add verb="*" validate="false" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler, Telerik.Web.UI"/>  
          <remove verb="*" path="*.asmx"/>  
          <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
          <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
          <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>  
          <add verb="GET" path="CaptchaImage.axd" type="Telerik.Web.UI.SpamProtection.Captcha.CaptchaImageHandler, Telerik.Cms.Web.UI"/>  
          <add verb="POST" path="blogs/metablog.ashx" type="Telerik.Blogs.MetaWeblog.MetaWeblogHandler, Telerik.Blogs"/>  
          <add verb="POST" path="trackback.ashx" type="Telerik.Cms.Engine.Trackback.TrackbackHandler, Telerik.Cms.Engine"/>  
          <add verb="GET" path="*.s3lb" type="Telerik.Libraries.AmazonStorage.S3StorageHandler, Telerik.Libraries"/>  
          <add verb="GET" path="*.s3lb.ashx" type="Telerik.Libraries.AmazonStorage.S3StorageHandler, Telerik.Libraries"/>  
          <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false"/>  
        </httpHandlers> 

    This is the Telerik section from my web.config:

    <handlers> 
          <remove name="ScriptResource"/>  
          <remove name="WebServiceHandlerFactory-Integrated"/>  
          <remove name="ScriptHandlerFactory"/>  
          <remove name="ScriptHandlerFactoryAppServices"/>  
          <remove name="SitefinityTemplate"/>  
          <remove name="SitefinityThumbnail"/>  
          <remove name="SitefinityLibrary"/>  
          <remove name="RadUploadProgress"/>  
          <remove name="SitefinityRSS"/>  
          <remove name="Dialog"/>  
          <remove name="Spellcheck"/>  
          <remove name="ChartImage"/>  
          <remove name="CaptchaImage"/>  
          <remove name="Metablog"/>  
          <remove name="Trackback"/>  
          <remove name="AmazonLibrary"/>  
          <remove name="AmazonLibraryAdd"/>  
          <remove name="SitefinityThumbnailAdd"/>  
          <remove name="SitefinityRSSAdd"/>  
          <remove name="SitefinityLibraryAdd"/>  
          <remove name="Telerik_Web_UI_WebResource_axd"/>  
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
          <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
          <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
          <add name="SitefinityTemplate" path="*.template" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32"/>  
          <add name="SitefinityThumbnail" path="*.tmb" verb="*" preCondition="integratedMode" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add name="SitefinityThumbnailAdd" path="*.tmb.ashx" verb="*" preCondition="integratedMode" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add name="SitefinityLibrary" path="*.sflb" verb="*" preCondition="integratedMode" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add name="SitefinityLibraryAdd" path="*.sflb.ashx" verb="*" preCondition="integratedMode" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>  
          <add name="SitefinityRSS" preCondition="integratedMode" verb="*" path="*.rss" type="Telerik.Rss.RssHttpHandler, Telerik.Rss"/>  
          <add name="SitefinityRSSAdd" preCondition="integratedMode" verb="*" path="*.rss.ashx" type="Telerik.Rss.RssHttpHandler, Telerik.Rss"/>  
          <add name="RadUploadProgress" verb="*" preCondition="integratedMode" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.Upload.RadUploadProgressHandler, Telerik.Web.UI"/>  
          <add name="Dialog" preCondition="integratedMode" verb="*" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI"/>  
          <add name="Spellcheck" preCondition="integratedMode" verb="*" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler, Telerik.Web.UI"/>  
          <add name="ChartImage" preCondition="integratedMode" verb="*" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler, Telerik.Web.UI"/>  
          <add name="CaptchaImage" preCondition="integratedMode" verb="GET" path="CaptchaImage.axd" type="Telerik.Web.UI.SpamProtection.Captcha.CaptchaImageHandler, Telerik.Cms.Web.UI"/>  
          <add name="Metablog" preCondition="integratedMode" verb="POST" path="blogs/metablog.ashx" type="Telerik.Blogs.MetaWeblog.MetaWeblogHandler, Telerik.Blogs"/>  
          <add name="Trackback" preCondition="integratedMode" verb="POST" path="trackback.ashx" type="Telerik.Cms.Engine.Trackback.TrackbackHandler, Telerik.Cms.Engine"/>  
          <add name="AmazonLibrary" path="*.s3lb" verb="*" preCondition="integratedMode" type="Telerik.Libraries.AmazonStorage.S3StorageHandler, Telerik.Libraries"/>  
          <add name="AmazonLibraryAdd" path="*.s3lb.ashx" verb="*" preCondition="integratedMode" type="Telerik.Libraries.AmazonStorage.S3StorageHandler, Telerik.Libraries"/>  
          <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource, Telerik.Web.UI"/>  
          <add name="DownloadHandler" verb="*" path="*.sflb.ashx" type="CustomCmsContentHandler, App_Code"/>  
        </handlers> 

    I use IIS6 on Windows 2003 R2

    Thanks,
    Daniel
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Nov 2009
    Link to this post
    Hello Daniel,

    You have to remove the default ContentHttpHandler from the web.config because it overrides the custom one. Once you remove the ContentHttpHandler declaration the custom handler will be accessed.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  17. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    27 Nov 2009
    Link to this post
    Hello Ivan,

    Thanks for your comments.
    I did remove the default content handler for *.sflb.ashx.

    <!--

     

    <add verb="GET" path="*.sflb.ashx" type="Telerik.Cms.Engine.ContentHttpHandler, Telerik.Cms.Engine"/>-->

     


    Unfortunatly it doesn't work on my live environment.
    Without removing this default handler it work correctly in my development environment, with the only difference that I don't use IIS there, but the built-in webserver of Visual Studio... :(

    -Daniel
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Nov 2009
    Link to this post
    Hi Daniel,

    You can take a look at MSDN to gather more information about registering HttpHandlers. Please follow the steps from this article.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  19. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    30 Nov 2009
    Link to this post
    Hi Ivan,

    Thanks for your suggestion.
    I followed the steps in the article, earlier, but with no success.

    Could it be that it has something to do with permissions?
    I set up the website in IIS also on my Dev box and there it works. Now I'm confused, because I really don't know the difference and also can't see the difference in IIS6?

    Hope you can help!

    Thanks,
    Daniel
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Nov 2009
    Link to this post
    Hello Daniel,

    According to MSDN Internet Information Services (IIS) passes requests for only certain file types to ASP.NET to service. Files with file-name extensions such as .aspx, asmx, and .ashx are already mapped to the ASP.NET ISAPI extension (Aspnet_isapi.dll). This applies to IIS 6.0, to IIS 7.0 running in Classic mode, and to managed handlers in IIS 7.0 that are running in Integrated mode. I suggest that you should check the IIS settings or create another sample handler and see whether the request is passed. I have no ideas what could be the reason for this behavior, also it is not spcifically related to Sitefinit or our API, because this is a standard .NET implementaton.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
20 posts, 0 answered