Skip to content


Just for the record: My name is Martin Helgesen. But I am planning to include my mothers family name which goes waay back: Brusevold. And when I created my gmail account,  martin.helgesen wasn’t available, but martin.brusevold was.

Everybody, say hello to Martin Brusevold Helgesen.


So it is all set.

I am returning to my hometown Sarpsborg again to work for an IT company there. Oslo was a nice place to work, but it’s very tempting to have 5 minutes of travel time to work, instead of 105 minutes. That means I will have over 3 hours of more spare time  in my daily schedule!

I have worked with many interesting and higly competent co-workers and customers. I will surely miss them. Anders Hattestad if you are reading this, thanks for all I’ve learned. You’re the best Episerver developer, no doubt.

Virtual Roles and access control in EPiServer

In some scenarios in EPiServer you may need to create your own logic for accessing specific pages. This can be done in several ways, but one of them is to implement your own Virtual Role. EPiServer default includes a set of virtual roles which are being used frequently.

Let’s say you have an open webportal in your company, no need to log in. And one department in the company, located in another part of the world, should see a set of pages (and its children), while the rest of the company should not. This department has specific IP addresses so we can recognize a request from this specific department from the IP address.

One solution would be to create a virtual role that compares the request IP to a set of pre-defined IP ranges (e.g from a config file). Let’s call this role “Employee”. you have to register it in web.config like this (added to the bottom after the default roles):

<virtualRoles replacePrincipal="true"> 
<add name="Administrators" type="EPiServer.Security.WindowsAdministratorsRole, EPiServer" /> 
<add name="Everyone" type="EPiServer.Security.EveryoneRole, EPiServer" /> 
<add name="Authenticated" type="EPiServer.Security.AuthenticatedRole, EPiServer" /> 
<add name="Anonymous" type="EPiServer.Security.AnonymousRole, EPiServer" /> 
<add name="Creator" type="EPiServer.Security.CreatorRole, EPiServer" /> 
<add name="Employee" type="YourType, YourAssembly" /> 

Then you have to create the implementation of the class. Inherit from the EPiServer.Security.VirtualRoleProviderBaseclass. Here is a class that compares the requests IP address:

public class EmployeeRole : EPiServer.Security.VirtualRoleProviderBase
public override bool IsInVirtualRole(IPrincipal principal, object context)
var clientIpAddress = HttpContext.Current.Request.UserHostAddress;
var validAddresses = new System.Xml.XmlDocument();
var isequal = validAddresses.SelectNodes("//IPSet/ip").Cast().Any(node =&gt; IsInRange(clientIpAddress, node));
return isequal;
}   private static bool IsInRange(string clientIpAddress, XmlNode node)
byte[] clientIP = IPAddress.Parse(clientIpAddress).GetAddressBytes();
byte[] mask = IPAddress.Parse(node.Attributes["mask"].Value).GetAddressBytes();
byte[] ip = IPAddress.Parse(node.Attributes["address"].Value).GetAddressBytes();
bool isequal = true;
for (int i = 0; i &lt; ip.Length; i++)
if ((clientIP[i] &amp; mask[i]) != ip[i])
isequal = false;
return isequal;

There you are finished creating your role! But how do you assign this role read-rights to a specific page and its subpages? Do it in edit mode. But first, you have to create a new group with the same name as the role you just created. EPi will then automatically associate this group with your created Virtual Role. After this, you can just add access rights for the group “Employee” to the pages in EPi you want.

New year. Great expectations

Hello everyone, my name is Martin and I work as a senior consultant in a IT  company located in Oslo, Norway.

I figured that since we now started a new year I will have set some goals for 2011. What will I achieve this year? It’s always nice to define goals. You can only get more experienced and the worst thing that can happen is not achieving your goals.

And for the record, adding a humongous number of goals will just result in lack of following up everyone of them, so if you want to be effective, concentrate on a few important.
Here is my list for 2011:

Writing tests
…the right way and be convinced that, hey, this is actually very useful! I’ve worked with legacy code several years now, and it’s soo hard to start writing tests on existing stuff. Hope I can join a new project from scratch very soon .

Hold several presentations
…that’s right, I want to challenge myself to keep presentations for an audience (not just working colleagues). You learn so much from this and evolve in many ways. Maybe it will be for the norwegian .net user group?

Keep track on myself
…on everything I do. How productive am I? How many new technologies or frameworks have I learned? How many books have I read? How many training hours a week? Guess it’s my way to try to optimize my life and how to live it. Measure, measure, measure.

Finishing a marathon
…in under 200 minutes (3:20:00). Yup, I’m a running man and I’ve finished several marathons and my personal best is 3:28:47. In Berlin, september this year,  I will be running the worlds fastest marathon track and I hope for a new record also 🙂

What’s your list like?