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

Forums / Developing with Sitefinity / How to remove special characters from URL

How to remove special characters from URL

5 posts, 0 answered
  1. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    26 Aug 2010
    Link to this post
    The following URL was generated from a News.

    http://redimob.com.br/News/Interna/10-08-25/Prédios_com_etiqueta_de_eficiência_energética_economizam_até_40_de_luz.aspx

    The problem is that some robots (like Facebook) can't access this page, because it can't read the page url properly.

    System.Web.HttpException: The file '/News/Interna/10-08-25/Prédios_com_etiqueta_de_eficiência_energética_economizam_até_40_de_luz.aspx' does not exist.
       at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
       at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
       at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
       at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
       at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
       at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
       at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    I was wondering if there is a way to convert characters like "é" to "e" and so on... Or some way to fix this...

    Is there a way I can fix it?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Aug 2010
    Link to this post
    Hello Bruno Michels,

    You have to use Server.URLEncode Method, but you should better key the url in English and create an additional metakey for the title. For more information and sample code, please check this post - Localized News

    Sincerely yours,
    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
  3. Filipe
    Filipe avatar
    7 posts
    Registered:
    20 Jul 2009
    10 Feb 2011
    Link to this post
    Hi Bruno.

    Did you resolve this problem?

    I´m using french language that also have special characters, didi you go with the Server.URLEncode Method solution or the "key the url in English and create an additional metakey for the title" solution?

    Can you send me an example.

    Send me a e-mail to abiliod@agap2.pt

    Obrigado.
  4. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    10 Feb 2011
    Link to this post
    I solved adding two triggers on sf_CmsContentBase

    CREATE TRIGGER [dbo].[SfCmsContentBaseOnInsert]
       ON  [dbo].[sf_CmsContentBase]
       AFTER INSERT
    AS
    BEGIN
        SET NOCOUNT ON;
         
        UPDATE sf_CmsContentBase
        SET [Url] = dbo.UrlDecodeUTF8(i.[Url]) collate SQL_Latin1_General_Cp1251_CS_AS,
            [LoweredUrl] = dbo.UrlDecodeUTF8(i.[LoweredUrl]) collate SQL_Latin1_General_Cp1251_CS_AS
        FROM sf_CmsContentBase c
        INNER JOIN inserted i on i.ID = c.ID
    END

    And

    CREATE TRIGGER [dbo].[SfCmsContentBaseOnUpdate]
       ON  [dbo].[sf_CmsContentBase]
       AFTER UPDATE
    AS
    BEGIN
        SET NOCOUNT ON;
         
        UPDATE sf_CmsContentBase
        SET [Url] = dbo.UrlDecodeUTF8(i.[Url]) collate SQL_Latin1_General_Cp1251_CS_AS,
            [LoweredUrl] = dbo.UrlDecodeUTF8(i.[LoweredUrl]) collate SQL_Latin1_General_Cp1251_CS_AS
        FROM sf_CmsContentBase c
        INNER JOIN INSERTED i on i.ID = c.ID
    END

    And you will need this function:

    CREATE FUNCTION [dbo].[UrlDecodeUTF8](@URL varchar(3072))
    RETURNS varchar(3072)
    AS
    BEGIN
        DECLARE @Position INT,
            @Base CHAR(16),
            @Code INT,
            @Pattern CHAR(21)
     
        SELECT @URL = REPLACE(@URL, '%c3', '')
     
        SELECT  @Base = '0123456789abcdef',
            @Pattern = '%[%][0-9a-f][0-9a-f]%',
            @Position = PATINDEX(@Pattern, @URL)
     
        WHILE @Position > 0
            SELECT @Code = Cast(CONVERT(varbinary(4), '0x' + SUBSTRING(@URL, @Position + 1, 2), 1) As int),
                @URL = STUFF(@URL, @Position, 3, NCHAR(@Code + 64)),
                @Position = PATINDEX(@Pattern, @URL)
     
        RETURN REPLACE(@URL, '+', ' ')
     
    END

  5. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    10 Feb 2011
    Link to this post
    Each time you edit the title the URL change. There isn't a permalink, it might be a good idea to implement a handler or something.
Register for webinar
5 posts, 0 answered