MVC returning ~/ in urls. Output filter?

Daniel Reed asked on July 13, 2015 10:44

Hi all,

I have an MVC controller querying some page HTML content and passing it to a page in JSON. When the content is returned, it has:

~/image.png

instead of:

http://site/image.png

Note that I don't mean converting relative links to absolute. This content is part of a large HTML block.

I need to convert these relative URLs in the content to absolute, and from my reading, it seems that Kentico usually applies output filters to change urls to absolute among other things.

Is there something I need to do in order to achieve this?

Correct Answer

Juraj Ondrus answered on July 23, 2015 09:59

Hi,

As far as I understand, you are retrieving some content with Kentico API and URLs are not resolved (specifically '~') for you since the Kentico output filter does not apply in MVC (which is responsible for this operation).

Our recommendation is not to change the way how CKEditor works, but change the way how you resolve the HTML code in your MVC application. In case you would like to resolve URLs programmatically, I would recommend to utilize HTMLHelper.ResolveUrls() method (Kentico 8.x).

Here is an example on how you can use this specific method:

                 string originalHTML = "";
                 string resolvedHTML = HTMLHelper.ResolveUrls(originalHTML, SystemContext.ApplicationPath);
0 votesVote for this answer Unmark Correct answer

Recent Answers


Daniel Reed answered on July 23, 2015 10:40

Thanks, that's exactly what I was after.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.