Stop URL's from being converted to absolute URLs?


While overall I love the new Telerik editor,the editor converts URLs to absolute URLs which doesn't work for me. How can I stop this? I find this behavior annoying for images,but it is even worse for anchors.

It makes it impossible to create links in KB articles to anchors within the KB article which is very important to me. For example, I have an anchor name "Example"on the bottom of a KB article. I then want to insert a link to this anchor at the top of the same KB article. The link I want is simply:

<a href="#Example">Link</a>

But the editor insists on changing this link to...

<a href="https://mydomain.com/KB/Staff/StaffEditArticle10001.aspx#Example">

This makes the link unusable to a viewer of the KB article.

Even worse,I can't even manually change it in HTML mode because the editor insists on changing the link back to the absolute one above. I know that this is just the MakeUrlsAbsolute content filter setting in the RadEditor so it should be relatively simple to create a configuration option to allow us to change this behavior.

Unfortunately,I can't figure out how to do this. I looked at the ConfigFile.xml in the RadControls folders and saw the following property which looked promising:

<property
name="StripAbsoluteAnchorPaths">true</property>,but this
setting didn't seem to have any effect.

Short of writing a trigger to strip these absolute,paths I am out of options. Is their any way to prevent the editor from converting these anchors to absolute (and unusable) paths?
Edited
10 Years Ago by Ryan Healey
InstantKB Question

This was really bugging me so I came up with an outside the box solution. This was a last resort, but these anchors are essential to me and I can't expect my KB editors to manually edit the html just to get anchors to work. My solution was to create a SQL trigger that will fix links to anchors on the same page whenever an article is created or updated.

I've included my trigger code below. Feel free to use it at your own risk.

And of course, before you even think about using it make sure you backup your database!

Also, make sure you thoroughly test this both by modifying existing articles and creating new ones.


USE [InstantKB]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER tgFixAnchorPaths
  ON  dbo.InstantKB_Articles
  AFTER UPDATE, INSERT
AS
    SET NOCOUNT ON;
  -- Trigger only fires if article body is updated
  IF UPDATE(ArticleText)
  BEGIN
    -- Set variables
    DECLARE @AbsPathPrefix varchar(1000), @AbsPathSuffix varchar(10), @RelativePath varchar(10)
    SET @AbsPathPrefix = 'href="https://yourdomain.org/YourPathToInstantKB/Staff/StaffEditArticle'
    Set @AbsPathSuffix = '.aspx#'
    Set @RelativePath = 'href="#'
    DECLARE @ArticleID int
    SELECT @ArticleID = ArticleID FROM Inserted
    -- Replace all occurrances of links to anchors on the page
    UPDATE dbo.InstantKB_Articles
    SET [ArticleText] = REPLACE(
      CAST([ArticleText] As varchar(max)),
      @AbsPathPrefix + CAST(@ArticleID As varchar(5)) + @AbsPathSuffix,
      @RelativePath
      )
    WHERE ArticleID = @ArticleID
  END


/*
Description
===========
Fixes anchor paths upon insert or update. Does this by removing the bogus
absolute path and leaving only the anchor.

Example:
Replaces "<a href="https://yourdomain.org/YourPathToInstantKB/Staff/StaffEditArticle10001.aspx#Anchor>Link</a>"
With "<a href="#Anchor>Link</a>"

Instructions
============
1. Modify the USE statement to match the name of your InstantKB database
2. Modify @AbsPathPrefix to fit your domain and path to the KB application
3. Create the trigger by running this code on your SQL server

History
=======
Created on 1 March 2010 by Tom Phelan

*/



Hi Tom,

Hope your very well. Sorry for my delay responding. Thank you for sharing your solution here on the forums :)

With InstantKB.NET we have a central class to mange the initialization &set-up of the RadEditor control.

You can modify this code with either the End User or Developer License.

You'll find the class within the InstantASP.InstantKb.UI project under the "hlpers"folder. The file is called TelerikHelpers.vb.

Taking a look at this code i can see we do explicitly set the "MakeUrlsAbsolute"content filter. I can;t recall exactly why we set this however i'll investigate this further and look at the possibility at removing this or at least making it optional.

To ensure the editor does not automatically convert your URLs to absolute URLs you may wish to try removing the following line from the TelerikHelpers class....

m_Editor.EnableFilter(Telerik.Web.UI.EditorFilters.MakeUrlsAbsolute)

You can find this line within the InitializeEditor method.

If your not able to recompile the DLL please don't hesitate to respond here and I'll attach an updated DLL with the changes applied.

Thanks for sharing your example Tom I'm sure others will find this very useful and I sincerely appreciate you taking the time to post it here.

I hope this information helps a little Tom. Of course if i can assist with any questions please don't hesitate to respond :)

http://www.instantasp.co.uk/images/line.gif
Kindest Regards,

Ryan Healey



ryan@instantasp.co.uk
www.instantasp.co.uk
Blog | Community | Docs

http://www.instantasp.co.uk/core/assets/images/email/facebook.png http://www.instantasp.co.uk/core/assets/images/email/twitter.png http://www.instantasp.co.uk/core/assets/images/email/google.png http://www.instantasp.co.uk/core/assets/images/email/linkedin.png
Edited
10 Years Ago by Ryan Healey

Ryan,

Thanks for the info. It's definitely helpful. I plan to make a list of little tweaks and then spend a day or so when I have time to modify code and recompile as needed.

The SQL trigger method only took 30 minutes to write and test so it was the quickest way for me to handle the issue. It will work fine until I get a chance to spend some time with the code.

It only took a few extra minutes to put it in a form that others could use so I figured I would post it here. I was a little hesitant because some developers are very finicky--often for good reason--about anyone suggesting backend changes like this. A poorly written trigger can do a lot of damage!

Again, thanks for the info.

GO

Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....







InstantASP Forums


Search