Vulnerability in EPiServer.Forms
I have a page type that has a property of type XhtmlString but this was previously of type string. For new pages or old pages that did not have the property set this is fine but for pages where the property value was set before the change I get an error Unable to cast object of type 'System.String' to type 'EPiServer.Core.XhtmlString' which I guess you would expect.
I can't remove the value, save the page and then add a new value in as the page hangs and will not allow save. So my question is how do I deal with this for older pages where the value was set before the change (other than deleting and recreating the page)?
I'm using 7.5 and it's MVC, I'm passing CurrentPage into the model.
Any suggestions appreciated.
Personally, I would have hidden the original property from edit mode, created a new xhtml property then migrate the string over to it in a scheduled job (or similar) meaning editors would not notice the difference and there would only be a single template change (for the new property name). You could also look at running some SQL against the DB though that is risky and tricky.
It depends on what's the current state of play. Do you have a production site where this is an issue or is this a development/test only issue at the moment? Are there 10's or 1000's of pages with the problem?
Can you let us know a little more about the current situation?
Thanks for your response. It's not in production yet but it will be shortly and I won't have access to the live environment (site or infrastructure) so any fix/workaround needs to be code based or SQL based if possible. The site I am seeing the issue on is our UAT site and there are about 2000 pages affected. I don't know how many pages of this type will be affected on the clients site, it could only be a few but I need to provide a solution just in case it's lots.
For information multiple properties on this page type have been changed from string to XhtmlString so although your suggestion reagrding hiding the property is a good one (one I'll try and remember next time!) I don't know if it would have been practical this time.
Thanks for your help,
I think I've fixed it using the following SQL:
UPDATE tblPropertyDefinitionSET fkPropertyDefinitionTypeID = 13WHERE fkContentTypeID = ( SELECT pkID FROM tblContentType WHERE Name = '[PageTypeName]' )AND fkPropertyDefinitionTypeID = 7AND Name IN ( '[Property1]', '[Property2]', Etc... )
Property definition type with ID of 7 is LongString and changing this to 13 changes it to XhtmlString
Naturally I backed up the database first!
I know that at least in EPiServer 9 the conversion is no problem. If it is an option to upgrade that is.
If you can't upgrade, you could also create a second pagetype with the same properties, change the ones that need changing and convert the pages with the old pagetype to the new one in admin mode >> Content Type >> Convert Pages.
Or use David's solution of course :)