Check if PageExternalURL exists


I'm creating pages in code and it looks like there is no built in function to check if a PageExternalURL already is used on another page. In edit mode there is a check for this but I'm now trying to find out what the best way would be to test this before saving the page.

I tried with the code below but I don't really know if this would be a satisfying way to go about. I don't seem to get any results in the PageDataCollection I get in return.

static public PageDataCollection FindPagesOfPageType(EPiServer.Core.PageReference pageLink, string pageExternalUrl)
    PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();
    PropertyCriteria criteria = new PropertyCriteria();
    criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
    criteria.Name = "PageExternalURL";
    criteria.Type = EPiServer.Core.PropertyDataType.String;
    criteria.Value = pageExternalUrl;
    criteria.Required = true;

    return DataFactory.Instance.FindPagesWithCriteria(pageLink, criterias);

Sep 01, 2010 8:19

You should be able to use the GlobalPageValidation.ValidateExternalURL event handler to do this (just create a new PageValidateEventArgs with your new page inside, call the handler with it and then check the EventArgs' IsValid property).

Could be it doesn't work for an unsaved page, I haven't tried. Post a reply if you get it working :)

Sep 01, 2010 8:31

All the ValidateExternalURL seems to do is making upper case characters to lower case. I can still save the page with an allready "occupied" PageExternalURL. As a little side note it also allows characters like €%&, while the function used in edit mode only allows a-z, 0-9, -, _ and ~.

Sep 01, 2010 8:50

I did a quick test and it seems to do exacly what is expected. This is the test code I used:

var page = DataFactory.Instance.GetDefaultPageData(PageReference.StartPage, 3);
page.PageName = "Test";
page["PageExternalURL"] = "test"; // An already used simple address
var args = new PageValidateEventArgs(page);
var isValid = args.IsValid; // false

I also tried an unused but illegal address ("#foo") and that also yields IsValid = false. The EventArgs also carries an errormessage describing the error correctly.

Sep 01, 2010 9:07

You are correct! I used it the wrong way. Thanks a million!

Sep 01, 2010 9:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.