Monday, January 25, 2016

C# - Get Top Level Domain name from Url


#Url from Episerver:
  string siteUrl = (SiteDefinition.Current.SiteUrl).ToString().TrimEnd(new []{'/'});
                var topUrl = siteUrl.Substring((siteUrl.Length - 2), 2);
              

With Javascript:
function getTopDomain(h) {
            return h.substring(h.length,h.length-2);
        }

Wednesday, December 16, 2015

EPiServer 7< - Programatically Create Pages with Blocks and Content Areas

Stuff we needed  before we get started:

  private static IContentRepository Repo  
     {  
       get  
       {  
         return ServiceLocator.Current.GetInstance<IContentRepository>();  
       }  
     }  

Create The page

 var DefaultPage= Repo.GetDefault<SOMEPAGETYPE>(SOMEPAGEREF, contentType.Load<SOMEPAGETYPE>().ID);  


Bind the properties you want added to you page.
Save the page (Needed because you cannot add blocks to a not saved page).


  var pageCopy= Repo.Save(DefaultPage, SaveAction.Publish, AccessLevel.NoAccess);  

To the pagecopy we need to find out the assetsFolder where we will add the blocks.


  var assetsFolder = ContentAssetHelper.GetOrCreateAssetFolder(pageCopy);  
  Repo.GetDefault<SomeBlock>(assetsFolder.ContentLink);  

Create block -  in assets folder then bind the data to the block and save it like this:


  Repo.Save(SomeBlock as IContent, SaveAction.Publish, AccessLevel.NoAccess);  

Then we need to get the created blocks from the assets folder and add them to ther contentArea. Something like this:


  foreach (var someBlockItem in Repo.GetChildren<SomeBlock>(assetsFolder.ContentLink))  
       {  
         var cAreaItem = new ContentAreaItem()  
         {  
           ContentLink = ((IContent)someBlockItem ).ContentLink  
         };  
         writableArea.Items.Add(cAreaItem);  
       }  
       pageCopy.SomeArea =  writableArea;   // (ContentArea Property)
      
       Repo.Save(pageCopy, SaveAction.Publish, AccessLevel.NoAccess);  

Thursday, December 10, 2015

EpiServer - Filter for pagetype properties of type string

 var properties = page.Property.Where(p => p.Type == PropertyDataType.String || p.Type == PropertyDataType.LongString);  

Tuesday, November 24, 2015

Node and Gulp global install

npm install
npm install gulp -g
npm install -g bower
npm install bower --save-dev
npm rebuild node-sass


bower install
bower update
Should yeild return:
cat .\bower.json

Tuesday, November 17, 2015

IIS - Changing frequentHitThreshold and TimePeriod for gzip for Improved Web Performance

serverRuntime attributeDescription
frequentHitThresholdNumber of times a URL must be requested within the time span specified in thefrequentHitTimePeriod attribute to be considered frequently hit. Must be between 1 and 2147483647. Default is 2.
frequentHitTimePeriodTime interval in which a URL must be requested the number of times specified in the frequentHitThreshold attribute before it is considered to be frequently hit. Default is 10 seconds.


Add the followgin Web.config
 <system.webServer>
    <serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="10:00:00" />



Unlock command in cmd (otherwise it won't work acess errors):

 C:\Windows\System32\inetsrv>appcmd.exe unlock config /section:system.webServer/s  
 erverRuntime  
 Unlocked section "system.webServer/serverRuntime" at configuration path "MACHINE  
 /WEBROOT/APPHOST".  

If this doesn't work try this:
%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/serverRuntime

Good Optimisation article:

Monday, November 16, 2015

Validate MD5 in Windows


In CMD just type:
CertUtil -hashfile <FILEPATH> MD5

will return the correct hash to validate against.


Tuesday, October 27, 2015

EPiServer - Apply Custom width to property in Episerver

I have highlighted the easy to miss syntax required to inject this styling.
  [EditorDescriptorRegistration(EditorDescriptorBehavior = EditorDescriptorBehavior.ExtendBase, UIHint="MakeLongerTextboxField",TargetType = typeof(string))]  
   public class WideTextboxEditorDescriptor : EditorDescriptor  
   {  
     public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)  
     {  
       base.ModifyMetadata(metadata, attributes);  
       metadata.EditorConfiguration.Add("style", "width: 800px!important");  
     }  
   }  

The Decorated Property:
 [UIHint("MakeLongerTextboxField")]  
     [Display(Description = "MetaDescription", GroupName = "SEO", Order = 104)]  
     public virtual string MetaDescription { get; set; }