EPiServer

You are currently browsing articles tagged EPiServer.

Jag och René Voigt vill hälsa alla intresserade välkomna till vårt första möte för EPiServerutvecklare i Stockholm. Vi har många intressanta saker att dela med oss med kring webbutveckling och EPiServer.

Boka den 12 maj efter jobbet i din kalender.

Inbjudan kommer med mejl på måndag med tid, plats och program till de som är medlemmar i nätverket för EPiServer-utvecklare i Stockholm.

Tags: , , , ,

EPiServer växer så det knakar och vi som utvecklar med produkten blir fler och fler. Jag tror tiden är mogen att dra igång ett fristående nätverk för EPiServer utvecklare!

Oavsett om man jobbar på ett litet eller stort företag finns det ett behov att dela erfarenheter och diskutera idéer kring webutveckling.

Med ett fristående forum kan vi som deltar själva sätta agendan. Är vi flera kan vi också påverka EPiServer.

Komma igång

Låt oss starta enkelt med att bara träffas efter jobbet. Anmäl ditt intresse att vara med på Meetup. När vi blivit några stycken bestämmer vi en tid och plats att träffas!

Skriv en kommentar nedan eller på Meetup-sajten  om du har förslag på ämnen att diskutera!

Tags: , , , ,

Nicklas Israelsson shared in his blog how you can exclude some name spaces from the EPiServer log to reduce the noise while debugging. A very useful tip! I would like to share how I use logging to collect exceptions (and debug info) in production.

How to setup production logging of Exceptions in EPiServer

Paste the example below into the EPiServerLog.config file in the root of your EPiServer application.

<?xml version="1.0" encoding="utf-8"?>
<log4net>

  <!-- Appender with one new log file per day -->
  <appender name="fileLogAppender"
            type="log4net.Appender.RollingFileAppender" >
    <file value="E:\EPiServerLog\www.example.com" />
    <encoding value="utf-8" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <staticLogFileName value="false" />
    <datePattern value=".yyyyMMdd.'log'" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level [%thread] %type.%method - %message%n" />
    </layout>
  </appender>

  <!-- Log page publish to find editor related errors. -->
  <logger name="EPiServer.DataAccess.PageSaveDB">
    <level value="DEBUG" />
  </logger>

  <!-- Removing all rows coming from OptimisticCache -->
  <logger name="EPiServer.Core.OptimisticCache" additivity="false">
    <level value="Off"/>
    <appender-ref ref="fileLogAppender" />
  </logger>  

  <!-- Send all errors to file. Level: Off, Fatal, Error, Warn, Info, Debug, All -->
  <root>
    <level value="Error" />
    <appender-ref ref="fileLogAppender" />
  </root>
</log4net>

TODO: You need to adjust the file-tag ("E:\EPiServerLog\") to an existing folder where the account used by your asp.net application are allowed to write. Also notice that backslash must be escaped.

lockingModel

Notice that this differs from what is shipped in the default EPiServerLog.config file (that does not work AFAIK).

file, rollingStyle, staticLogFileName, datePattern

These tags configures one file per day in the folder specified by the file-tag. I prefer to set staticLogFileName to false even if true might get some better performance.

level

Change level from Error to Debug or All if you need more data when you debug. Do remember to change it back to Error when you are done because your files grow fast and using reflection to find type and method steals some CPU-time, too.

Tags: ,

How do you inject dynamic content into your web page? Following is a list of the most common methods I find when doing quality and code reviews with some comments and dangerous pitfalls.

#1: Inline Expressions with Code Render Blocks

Using inline expressions is a shortcut for calling the Write method.

Example – DONT:

<h2><%= CurrentPage.PageName %></h2>
<img src="<%= CurrentPage["ImageUrl"] %>" alt="<%= CurrentPage["MainIntro"] %>" />
<div class="mainarea">

     <%= CurrentPage["MainBody"] %>
</div>

Since xhtml is just text, writing some more in-between existing static blocks is fast and simple. Probably the easiest way to inject dynamic content but it is also dangerous!

Example – DO always use HtmlEncode:

<h2><%= HttpUtility.HtmlEncode(CurrentPage.PageName) %></h2>

What happens if our PageName property contains a “<” or “&” character in the example above? Your page will not validate and you risk that it breaks down. It can also be exposed to script injection if the content is user generated.

To be on the safe side you should always call HttpUtility.HtmlEncode on all strings that you inject with inline expressions.

Example – DO always use a fallback for src-attributes

<img src="<%= CurrentPage["ImageUrl"] ?? "/Missing.png" %>" />

If your ImageUrl property is empty you would get a img-tag with an empty src-attribute. This can lead to the page being rendered twice. FireFox interpret a null src-attribute a relative url and evaluate it using the page url as base returning the same url.

#2: With EPiServer:Property web control

Using the EPiServer Property Web Controls instead of inline expressions has several benefits. It could be used for rendering the PageName and MainBody in the example above.

Example – DO use EPiServer:Property web control

<h2><EPiServer:Property PropertyName="PageName" runat="server" /></h2>
<EPiServer:Property CssClass="mainarea" PropertyName="MainBody" runat="server" />

1) When rendering EPiServer’s ToWebString() is used. This does almost the same job as always calling HtmlEncode yourself.

public virtual void CreateDefaultControls()
{
    Label target = new Label();
    target.Text = PropertyData.ToWebString();
    CopyWebAttributes(target);
    Controls.Add(target);
}

2) It enables the Simple Edit feature for the editors without any extra work. (If you do not know what “Simple Edit” is, you should read the Editors Manual for EPiServer before doing any more development.)

3) Different types have get different rendering automatically. Commonly used for PageReferences and Url’s that are rendered as a Hyperlink.

Example – DO use EPiServer:Property for rendering links if possible

<EPiServer:PageList PageLinkProperty="NewsArchivePage" MaxCount="5" runat="server" >
  <HeaderTemplate>
    <h3><EPiServer:Property PropertyName="PageLink" runat="server" /></h3>
    <ul>
  </HeaderTemplate>
  <ItemTemplate>
    <li><EPiServer:Property PropertyName="PageLink" runat="server" /></li>
  </ItemTemplate>
  <FooterTemplate>
    </ul>
  </FooterTemplate>
</EPiServer:PageList>

4) Use PageLinkProperty to follow a Page-property to another page and render a value. Takes care of all hassle and calls GetPage() and check for nulls for you.

Example – DO use EPiServer:Property to render values from another page

<h3><EPiServer:Property PageLinkProperty="FeatureArticlePage" PropertyName="PageLink" runat="server" /></h3>
<div><EPiServer:Property PageLinkProperty="FeatureArticlePage" PropertyName="MainIntro" runat="server" /></div>

Tags: , , , , ,

We need more help. There has been a lot of things to do lately so I have not been able to blog as much as I want to but after release I have a lot of things to share with you all.

Problems with WebParts in EPiServer CMS R2?

Disappearing WebParts after upgrading a project to R2 is one of the fun things I have solved. It is related to serialization and reducing the number of assemblies by moving classes. I have a workaround if you need – just drop me a line…

EPiServer Developer position open at INEXOR AB

My employer is looking for more EPiServer Developers to hire. Even if the job ad is in Swedish, the working language is English so let us know if you are looking for a new job.

Tags: , ,

« Older entries § Newer entries »