A lot of times we come across an issue when we forgot Episerver administrator password in our local environment or if we have restored the database from other environments and we might don’t know its administrator user name and password.

The following steps show you an easy way to generate new Episerver administrator user in your local environment. This method only works if you are using Episerver to provide membership authorization. If you are using Azure AD or any third party SSO (Single Sign-on) then the below method wouldn’t work. I’ll create a new blog post to provide a solution.

Please use any text editor such as Notepad to create an empty .aspx file and copy and paste the following code in this file. Copy this file in the Website root folder and access it through the browser.

<%@ Page Language="C#" AutoEventWireup="true" %> 
<% 
   try 
   { 
      Roles.CreateRole("Administrators"); 
   } 
   catch (Exception) { } 
   try 
   { 
      var user = Membership.CreateUser("adminuser", "adminuser", "admin@episerver.com"); 
      user.IsApproved = true; 
    }
    catch (Exception) {}
    try
    {
        Roles.AddUserToRole("adminuser", "Administrators"); 
    }
    catch (Exception) {} 
%> 

The above code will check if the website has an administrator group. If the website does not has an administrator group then this code will create this group. The next code snippet will create a user “adminuser” with the same password and assign the user to “administrator” group.

The above code will only work if your default membership provider is Episerver and you have VirtualRole of “Administrator” enabled in “episerver.framework”.

I found the above solution in the Episerver forum a long time ago and it still works.

Categorized in: