Keep your web editors in the loop!

In EPiServer

For us as developers it’s important to log errors that occur on a website. We do this in ASP.NET and  EPiServer through either debugging during the development phase, or implementning log management through writing to the event log or utilizing log4net.

puzzle This post is about letting web editors know that something has gone wrong, and what they can do to resolve the error. Parallell to this we do not wish to display a full error message for website visitors. They should be made aware why the page isn’t working, but not given any specifics.

The scenario

Let’s say you’ve just created a website using EPiServer CMS. The website implements an RSS-reader page. The web editor might enter a feed address which is not valid which generates an error. We do not wish to display the full error message for any visitors that browse the feed page. The web editors, however, should be alerted that everything is not well in web land and what might be the cause of this.

We need to implement the following functionality:

  • Check if the current user is a web editor
  • Display the full error message only if the current user has the appropriate permission set

Is the current user a web editor?

Through the ASP.NET provider model and the PrincipalInfo class in EPiServer.Security we can check if the current user has edit permission to the page.

This enables us to modify the error message according to the user’s access level.

Let’s package it!

Duplicating code is never good practice. So let’s have a look at how we could package this into a simple server control.

To use the control on a page you’ll need to use the Register page directive.

On the page you add it like an ordinary control.

You can either set the error message in markup or in the code-behind file. In this scenario I’m catching an WebException when the RSS-feed cannot be loaded.

The result

And here is what it’ll look like if the RSS-feed URL is incorrect and a visitor browses the page.

 image

And when an administrator or web editor views the page (granted they’re logged in, of course!) the result is slightly different.

 image

daniel
daniel
Developer
Recent Posts
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Start typing and press Enter to search