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

Forums / Developing with Sitefinity / Url Redirecting to Libraries

Url Redirecting to Libraries

6 posts, 0 answered
  1. Jan
    Jan avatar
    2 posts
    Registered:
    02 Jul 2008
    18 Sep 2008
    Link to this post
    Hi,

    I have uploaded mp3 files into a Sitefinity Library and would like to link to it with the .mp3 extension instead of using .sflb

    In the web.config I add the following:
    <rewriterConfiguration>
        <rewriterRules>
            <add lookFor="~/Libraries/(.*).mp3" sendTo="~/Libraries/$1.sflb?download=true"/>
        </rewriterRules>    
    </rewriterConfiguration>
    Since I am handling this extension in asp.net I have to add the application mapping in IIS. Since I am doing this I no longer can browse to an mp3 file on the website file system, I get a page not found error. I tried adding the following after the above entry without success:
    <add lookFor="~/(.*).mp3" sendTo="~/$1.mp3"/>

    Any ideas?

    Thanks,
    Jan
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 May 2017
    24 Sep 2008
    Link to this post
    Hello Jan,

    Thank you for contacting us.

    All uploaded files are stored in the database and ASP.NET handles the requests for the files ending with .sflb. That is the reason why it is not possible to use UrlRewriter. To solve the issue you need to create a class extending ContentHttpHandler base class and override ProcessContentItem method. To achieve this follow the steps below:

    1. Create App_Code folder in your project root.

    2. Add a new class - CustomCmsContentHandler.cs

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.Cms.Engine; 
    using System.Web.Hosting; 
     
    /// <summary> 
    /// Summary description for CustomCmsContentHandler 
    /// </summary> 
    public class CustomCmsContentHandler : ContentHttpHandler 
        protected override void ProcessContentItem(IContent content) 
        { 
            string extension = VirtualPathUtility.GetExtension(HttpContext.Current.Request.Url.AbsolutePath); 
            if (extension.Equals(".mp3", StringComparison.OrdinalIgnoreCase) 
                && !content.MimeType.StartsWith("audio/")) 
            { 
                throw new HttpException(404, "Not found"); 
                return
            } 
            base.ProcessContentItem(content); 
        } 

    3. Add the ISAPI filter for .mp3 extension into the IIS configuration. This will modify your web.config as follows:

    <add name="mp3handler" path="*.mp3" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> 

    4. Declare the following httphandler in the <httpHandlers> section of the project web.config.

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

    Hope this helps

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Pallavi
    Pallavi avatar
    2 posts
    Registered:
    24 Jun 2010
    25 Jun 2010
    Link to this post
    Hello,

    We had the same and tried following the approach that  Ivan listed out. The CustomCmsContentHandler  class seems to have some issues. Can someone please confirm if this has worked ?

    Thank You.
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    25 Jun 2010
    Link to this post
    Hi Pallavi,

    Please make sure that the handler is registered in the appropriate sections in web.config. For IIS6.0 it is sytem.web/httpHandlers for IIS7.0 the section is system.webServer/handlers. The handler has been tested and works.

    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Pallavi
    Pallavi avatar
    2 posts
    Registered:
    24 Jun 2010
    25 Jun 2010
    Link to this post
    Hello Radoslav,

    Thank you for replying.
     As far as the handler registration goes, got that part right but  had trouble running the class successfully. The class states overriding 'ProcessContentItem'  with only IContent item as parameter, but the method takes two parameters (Icontent item  and request object).
    any help in clarifying the handler class will be appreciated.

    Regards,
    Pallavi
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 May 2017
    27 Jun 2010
    Link to this post
    Hello Pallavi,

    Below is the modified method

    protected override  object ProcessContentItem(IContent content, HttpRequest request)
        {
            object data = content.Content;
            string extension = VirtualPathUtility.GetExtension(HttpContext.Current.Request.Url.AbsolutePath);
            if (extension.Equals(".mp3", StringComparison.OrdinalIgnoreCase)
                 && !content.MimeType.StartsWith("audio/"))
            {
                throw new HttpException(404, "Not found");
                return
            }
            return base.ProcessContentItem(content, HttpContext.Current.Request);
        }


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered