Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

How to construct URL from string

Vote:
 

I have an image URL as a property for a page, and I would like to set a default value for the property. What is the best way to do this? Here is what I have tried so far:

public class StandardPage : PageData
{
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
BannerImage = new Url("/Static/img/banner_300.jpg");
}

[UIHint(UIHint.Image)]
public virtual Url BannerImage { get; set; }

...
}

But that renders as src="/Views/Shared/32". which I think is a ContentReference to the same image which was uploaded using the file system. The URL for that item should be "/globalassets/banner-images/banner_300.jpg", which would also work, but how can I create an item of type EPiServer.Url with a local path based on a provided string?

 

#83039
Mar 25, 2014 9:51
Vote:
 

I have figured out what was wrong. I changed the property from a ContentReference to a Url, but had already set a default value using the admin interface. This was then overriding the default set in code. The page model above now works.

#83046
Edited, Mar 25, 2014 10:46
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.