London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Episerver - make the page url read only

Vote:
 

In Episerver 7.19 I need to make the field for the url in the header of a page in episerver read only for some pages so that the developers can hard code the url:s instead

#122941
Jun 18, 2015 12:50
Vote:
 

Hi!

[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = EPiServer.Web.UIHint.PreviewableText)]
public class ReadOnlyUrlSegmentEditorDescriptor : EditorDescriptor
{
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
    {
        base.ModifyMetadata(metadata, attributes);

        if (metadata.PropertyName.Equals("iroutable_routesegment", StringComparison.InvariantCultureIgnoreCase))
        {
            if (metadata.ContainerType == typeof (MyPageType))
            {
                metadata.IsReadOnly = true;
            }
        }
    }
}
#122948
Jun 18, 2015 14:33
Vote:
 

Thank you, but is it possible to decide in the code what the url should be for each individual page of the same pagetype?

#122951
Jun 18, 2015 15:01
Vote:
 

On your page type definition class you can try to override the SetDefaultValues method like this and set the URLSegment property on the page explicitly. Something like this (untested):

public override void SetDefaultValues(EPiServer.DataAbstraction.ContentType contentType) 
{
    base.SetDefaultValues(contentType);
    this.URLSegment = "my-hard-coded-url";
}

Be careful though, you don't want multiple child nodes with the same URLSegment.

#122953
Edited, Jun 18, 2015 15:07
* 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.