<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Henrik Molnes</title><link href="https://world.optimizely.com/blogs/Henrik-Molnes/" /><updated>2016-10-25T18:59:49.5700000Z</updated><id>https://world.optimizely.com/blogs/Henrik-Molnes/</id><generator uri="https://world.optimizely.com/blogs/Henrik-Molnes/" version="2.0">Optimizely World</generator><entry><title>Disable rendring of a block based on it's content</title><link href="http://henrikm.com/disable-rendring-of-a-block-based-on-its-content/" /><id>http://henrikm.com/disable-rendring-of-a-block-based-on-its-content/</id><published>2014-10-17T07:50:00.0000000Z</published><updated>2016-10-25T18:59:49.2100000Z</updated><author><name>molnes@gmail.com</name></author><category term="Blog post" /><summary type="html">&lt;p&gt;Let's say we have a block defined like below. The problem that need to be solved occurs when the property &lt;code&gt;ContentBlockLink&lt;/code&gt; is pointing to a page that the user does not have access to. Could be because of StartPublish, &lt;a href="/link/fdb75bbf65194537ab48e7f8de72a9a6.aspx"&gt;role membership&lt;/a&gt; or something else. Then the whole block should not be visible for the user.&lt;/p&gt;

&lt;script src="https://gist.github.com/hmol/ce538ddf85c62f6ff579.js"&gt;&lt;/script&gt;

&lt;p&gt;Instead of having the &lt;em&gt;don't-render-me&lt;/em&gt; logic in the view, factory or the controller, the best place to disable the rendering would in fact be inside the &lt;code&gt;Render()&lt;/code&gt; method of &lt;code&gt;IContentRendrer&lt;/code&gt;. This method is respoinsible for rendering all blocks. Could be done like this:&lt;/p&gt;

&lt;script src="https://gist.github.com/hmol/7ef7e18ebcfca5c01fbc.js"&gt;&lt;/script&gt;

&lt;p&gt;To be able to use &lt;code&gt;CustomContentRenderer&lt;/code&gt; you need to swap it with the default &lt;code&gt;ContentRendrer&lt;/code&gt;. This is done by using dependency injection. A good example on doing it with StructureMap is seen here: &lt;br /&gt;
&lt;a href="https://github.com/kennethdevik/alloytechazure/blob/master/AlloyTechAzure/Business/Initialization/DependencyResolverInitialization.cs"&gt;https://github.com/kennethdevik/alloytechazure/blob/master/AlloyTechAzure/Business/Initialization/DependencyResolverInitialization.cs&lt;/a&gt;&lt;/p&gt;</summary></entry><entry><title>Custom validation of properties in EPiServer 7</title><link href="http://henrikm.com/custom-episerver-property-validation/" /><id>http://henrikm.com/custom-episerver-property-validation/</id><published>2014-10-09T16:00:00.0000000Z</published><updated>2016-10-25T18:59:49.5700000Z</updated><author><name>molnes@gmail.com</name></author><category term="Blog post" /><summary type="html">&lt;p&gt;In EPiServer 7 (and newer versions) developers can easlily validate input from editors and display a message. There are 3 different severities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ValidationErrorSeverity.Info&lt;/code&gt;&lt;img src="http://henrikm.com/content/images/2014/Sep/info.png" alt="" title="" /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ValidationErrorSeverity.Warning&lt;/code&gt;&lt;img src="http://henrikm.com/content/images/2014/Sep/warning.png" alt="" title="" /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ValidationErrorSeverity.Error&lt;/code&gt; (Page cannot be saved)&lt;img src="http://henrikm.com/content/images/2014/Sep/error.png" alt="" title="" /&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Implementing custom validation of properties in code can be done in two different ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Validation of all properties that are assigned with a custom attribute. This only supports &lt;code&gt;ValidationErrorSeverity.Error&lt;/code&gt;   &lt;script src="https://gist.github.com/hmol/6c7a955df0af56e0f4bd.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validation of properties that exists on a specific pagetype. Supports all 3 severities.   &lt;script src="https://gist.github.com/hmol/37ddf2e060e808afd88b.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;br /&gt; &lt;br /&gt;
Other relevant reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.david-tec.com/2012/06/EPiServer-7-Preview---Using-validation-attributes/"&gt;http://www.david-tec.com/2012/06/EPiServer-7-Preview---Using-validation-attributes/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.david-tec.com/2012/06/EPiServer-7-Preview---IValidator-interface/"&gt;http://www.david-tec.com/2012/06/EPiServer-7-Preview---IValidator-interface/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/link/52c750a171ee49ada7103835315dfa08.aspx"&gt;http://world.episerver.com/Blogs/Alexander-Haneng/Dates/2012/7/How-to-define-properties-in-EPiServer-7---A-quick-reference/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/link/f4d86e3ecfad4be8aa4a1e55d5fae6df.aspx"&gt;http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2013/12/Restriction-of-content-types-in-properties/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</summary></entry><entry><title>Using VppMigrationTool returns exception (Could not load file or assembly..)</title><link href="https://world.optimizely.com/blogs/Henrik-Molnes/Dates/2014/2/Using-VppMigrationTool-returns-exception-Could-not-load-file-or-assembly/" /><id>https://world.optimizely.com/blogs/Henrik-Molnes/Dates/2014/2/Using-VppMigrationTool-returns-exception-Could-not-load-file-or-assembly/</id><published>2014-02-17T10:56:39.0000000Z</published><updated>2014-02-17T18:45:54.5830000Z</updated><author><name>molnes@gmail.com</name></author><category term="Blog post" /><summary type="html">&lt;p&gt;&lt;font size="4"&gt;This is migth be a bit too specific, but when using the VppMigrationTool to migrate files to EPiServer 7.5 I got this error when trying to connect to the site:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://henrikm.com/epiimgs/VppMigrationTool_E4A7/Capture.png"&gt;&lt;img title="Capture" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Capture" src="http://henrikm.com/epiimgs/VppMigrationTool_E4A7/Capture_thumb.png" width="554" height="575" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p style="height: 96px; width: 100.78%"&gt;&lt;font size="3" face="Consolas"&gt;Could not load file or assembly 'file:///C:\Users\pa_hemo\Downloads\EPiServer_7.5_VppMigrationTool\VppMigrationTool_20140107.1\VppMigrationTool.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) &lt;font size="3" face="Consolas"&gt;at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp;amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="4" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="4" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="4"&gt;At the bottom of the exception you get a little hint, but it took me&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="4"&gt;some minutes to figure it out. The solution is to add the config settings below in to your &lt;font face="Consolas"&gt;Machine.config-&lt;/font&gt;&lt;font face="Calibri"&gt;file:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;pre&gt;&lt;font size="4" face="Consolas"&gt;&amp;lt;configuration&amp;gt;
   &amp;lt;runtime&amp;gt;
      &amp;lt;loadFromRemoteSources enabled=&amp;quot;true&amp;quot;/&amp;gt;
   &amp;lt;/runtime&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;This did the trick for me :)&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;You can also change the &lt;font face="Consolas"&gt;VppMigrationTool.exe.config&lt;/font&gt;&amp;#160; to look like this:&lt;/font&gt;&lt;/p&gt;

&lt;pre style="height: 304px; width: 100%"&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;lt;configuration&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;#160;&amp;#160; &amp;lt;startup&amp;gt; &lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;supportedRuntime version=&amp;quot;v4.0&amp;quot; sku=&amp;quot;.NETFramework,Version=v4.0&amp;quot;/&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;#160;&amp;#160; &amp;lt;/startup&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;#160;&amp;#160; &amp;lt;runtime&amp;gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;loadFromRemoteSources enabled=&amp;quot;true&amp;quot;/&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;#160;&amp;#160; &amp;lt;/runtime&amp;gt; &lt;/font&gt; &lt;/p&gt;&lt;p&gt; &lt;font size="3"&gt;&amp;lt;/configuration&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;/pre&gt;

&lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;
  

  

  &lt;p&gt;&lt;font size="4"&gt;&lt;/font&gt;&lt;/p&gt;

  &lt;p&gt;&lt;font size="4"&gt;PS: You should also be aware that VppMigrationTool removes the config-settings from web.config for the folders you choose migrate.&lt;/font&gt;&lt;/p&gt;&lt;/p&gt;</summary></entry></feed>