EPiServer - how to create admin users from the code

Every time we create a new EPiServer website, we usually have to create admin user as well.

There are many ways to do this, but creating users and roles manually is not much fun.

I wrote a small script for this job which will do the following:

- Check if WebAdmins role exists. If not, create one
- Check if Administrator user exists. If not, create one
- Assign WebAdmins role to Administrator

Here's the source code:

<%@ Page Language="C#" AutoEventWireup="true" %>
    var adminRole = "WebAdmins";
    var username = "Administrator";
    var password = "Administrator";
    var email = "admin@localhost.com";
if (!Roles.RoleExists(adminRole))
if (Membership.GetUser(username) == null)
    var user = Membership.CreateUser(username, password, email);
    user.IsApproved = true;
Roles.AddUserToRole(username, adminRole); %>

And you can also download it from this link: backdoor.zip

How to use it

All you have to do is to place this file under wwwroot folder like this:

You don't have to include it in your solution.

Then simply navigate to that file:

And it will create a user for you:

Don't forget to remove the file from wwwroot folder.

comments powered by Disqus