0

I have a section that saves html created with an html editor into a database in the site control panel.

in my html if I insert image with this address "image/Picture1.jpg" using the html editor if there is a image stored at mysite.com/image/picture1.jpg.

Now in a view(razor) I display the stored html content from the database with System.Web.HttpUtility.HtmlDecode or @Html.Raw(item.Content). if this content is shown the in home page like mysite.com it works correctly.

but, if it show it in other area or controller or action the image doesn't show. Because in those areas (like mysite.com/desktop) the image address changes to mysite.com/desktop/image/picture1.jpg.

How do I display this html content without this problem?

0

1 Answer 1

1

The images will always be relative to the page that displays them as you are using a relative URL.

Unless they have an absolute URL mysite.com/image/picture1.jpg or a root-relative URL /image/picture1.jpg in the HTML it will not work.

A: You need to enter the URL in the HTML editor as either absolute

mysite.com/image/picture1.jpg

or root-relative:

/image/picture1.jpg

In both cases the browser will search from root of the website, and not just relative to the current page.

Sign up to request clarification or add additional context in comments.

8 Comments

does not exist any method or command that find link like ~/... or /.. and change to site.com/...? because I have many data that stored in database from old version of my site. and now I have problem with old data in new version(mvc version)
You can inject the website base URL into a page element using @Url.Content("~/") or assign a variable injected in a tiny page script, but it sounds like you need to process the HTML before you display it. Are they just stored in the html as <img src="image/picture1.jpg/> etc?
Yes I need to process the html but I think maybe there's a way for this problem. because there is more than 1000 pages for check.
If they are standard <img tags you can use a RexEx to match and replace the src= urls with fixed versions.
Need a sample HTML page to provide example
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.