Hi Martin
Have you tried creating a clean Alloy site using the Episerver Visual Studio extension? This uses ASP.net Identity by default (and has a controller that sets a new user up if none are configured).
It may be worth comparing the code against that in the post to see if anything is missing?
David
Hi Martijn,
Do you need an initialization module or one-time thing?
Perhaps you could create an aspx page (userregistration.aspx) and drop it to the web root:
<%@ Page Language="C#" AutoEventWireup="true" %> <%@ Import Namespace="EPiServer.ServiceLocation" %> <%@ Import Namespace="EPiServer.Shell.Security" %> <% string adminRole = "WebAdmins"; string username = "admin"; string password = "Administrator123!"; string email = "noreply@localhost.no"; var userProvider = ServiceLocator.Current.GetInstance<UIUserProvider>(); var roleProvider = ServiceLocator.Current.GetInstance<UIRoleProvider>(); int userCount; userProvider.GetAllUsers(0, 1, out userCount); if (userCount > 0) { Response.Write("Database already contains users."); return; } UIUserCreateStatus status; var errors = Enumerable.Empty<string>(); userProvider.CreateUser(username, password, email, string.Empty, string.Empty, true, out status, out errors); if (status == UIUserCreateStatus.Success) { roleProvider.CreateRole(adminRole); roleProvider.AddUserToRoles(username, new[] { adminRole }); Response.Write("Created 'admin' user"); return; } Response.Write("Failed to create user"); %>
When you navigate to yourdomain.com/userregistration.aspx, it will check if the database already contains users.
If not, it will create WebAdmins group and a user (username: admin, password: Administrator123!) that is a member of that group.
This aspx file doesn't even have to be included in the project (.csproj) and can be deleted right after the user is created.
Seems like administrator.IsApproved is set to false as default. I set the property to true and was able to login with this example.
Hello readers,
I'm working on implementing ASP.NET Identity in an EPiServer project, following this tutorial: http://world.episerver.com/documentation/developer-guides/CMS/security/episerver-aspnetidentity/
In order to create an initial user I made an 'InitializeModule', like this:
I can validate that the user (and roles) get added by looking at the database content.
When I try to login at site-url/episerver and use the credentials for the admin user, it won't let me login.
I have triple-checked the actions described in the blogpost, but I'm sure I've followed the instructions, yet it doesn't work.
Does anyone know how to fix my issue?
Greetings,
Martijn