November Happy Hour will be moved to Thursday December 5th.

Switch to SqlServerMembershipProvider

Vote:
 

When I created the latest project I got WindowsRoleProvider by default. I guess switching is not a problem but I can't find how to add that first user. I remember it's something along the lines of right clicking the project in Visual Studio but I can't seem to find it. Has this been moved from the 2010 version? I'm in 2013 now.

#86653
May 27, 2014 20:31
Vote:
 

If you want to switch from Windows to Sql provider -> you need to change it in web.config. Find <membership> and <roleManager>. You most probably will have MultiplexProvider set by default. You need to configure it in order to set Sql providers in first place.

#86655
May 27, 2014 20:55
Vote:
 

And as for adding the first user. If you are using MultiplexProvider you will be able to log in with your windows account and then create a sql user. After that you can do the switch as Valdis showed.

#86660
May 27, 2014 21:31
Vote:
 

Hi bmdeveloper,

You can find that option under PROJECT / ASP.NET Configuration

http://dcaric.com/ew-images/20140528/project.png

Creating users and roles manually is boring :) So I created this small tool:

<%@ Page Language="C#" AutoEventWireup="true" %>
<%
	var adminRole = "WebAdmins";
	var username = "Administrator";
	var password = "Administrator";
	var email = "admin@localhost.com";


if (!Roles.RoleExists(adminRole))
{
	Roles.CreateRole(adminRole);
}

if (Membership.GetUser(username) == null)
{
	var user = Membership.CreateUser(username, password, email);
	user.IsApproved = true;
}

Roles.AddUserToRole(username, adminRole); %>

<p>Done!</p>

You can name this file backdoor.aspx and place it under wwwroot folder like this:

http://dcaric.com/ew-images/20140528/root.png

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

It will create a user called Administrator, password Administrator, and assign it to WebAdmins group.

All you have to do next is to simply navigate to that file:

http://dcaric.com/ew-images/20140528/url.png

And it will create a user for you:

http://dcaric.com/ew-images/20140528/admin.png

Hope this helps!

Edit: Image upload doesn't work, so I'm posting links.

#86669
Edited, May 28, 2014 10:18
Vote:
 

Nice! Just remember to remove file from production server if accidently deployed :)

#86671
May 28, 2014 10:25
Vote:
 

I've swaped the providers to the two SQL server providers and I pasted Dejans code into the page load of my masterpage. It still won't let me log in, though. I put breakpoints in the code and I can see that the user I created exists since it didn't try to create neither the group or user at new. What's the problem here?

By the way, brilliant way to do it, Dejan!

#86712
May 28, 2014 19:51
Vote:
 

If I change the provider back to Multiplexing I can log in using my Windows Membership but not the accounts provided by SQL. When I go to "Search User/Group" in admin mode and press search I get a notification saying:

"Item has already been added. Key in dictionary: 'test' Key being added: 'test'"

I tried adding a three different accounts and test was one of them. Still, no user shows up in the search result. If I search for groups I see the WebAdmins group that was created in the code and when I look at the members of it I only get one line, a blank one.

How is this possible?

#86713
May 28, 2014 20:06
Vote:
 

Does anything below need editing?

<virtualRoles replacePrincipal="true">
      <providers>
        <add name="Administrators" type="EPiServer.Security.WindowsAdministratorsRole, EPiServer.Framework" />
        <add name="Everyone" type="EPiServer.Security.EveryoneRole, EPiServer.Framework" />
        <add name="Authenticated" type="EPiServer.Security.AuthenticatedRole, EPiServer.Framework" />
        <add name="Anonymous" type="EPiServer.Security.AnonymousRole, EPiServer.Framework" />
        <add name="CmsAdmins" type="EPiServer.Security.MappedRole, EPiServer.Framework" roles="WebAdmins, Administrators" mode="Any" />
        <add name="CmsEditors" type="EPiServer.Security.MappedRole, EPiServer.Framework" roles="WebEditors" mode="Any" />
        <add name="Creator" type="EPiServer.Security.CreatorRole, EPiServer" />
        <add name="PackagingAdmins" type="EPiServer.Security.MappedRole, EPiServer.Framework" roles="WebAdmins, Administrators" mode="Any" />
      </providers>
    </virtualRoles>
#86714
May 28, 2014 20:10
Vote:
 

Never mind. I forgot the row to add the user to the role.... :$

Thanks, guys!

#86716
May 28, 2014 20:27
Vote:
 

While we're on the subject; now that I've manage to switch to SqlMembershipProvider every page in edit mode says "You have not been assigned the user rights to make chhanges to this page". What else do I need to do to get this working? Creating a "webeditors" group was not enough.

#86726
May 29, 2014 5:28
Vote:
 

Double check user access rights for the pages. CMS -> Admin -> Admin -> Access Rights

#86727
May 29, 2014 5:37
Vote:
 

I had the group names mixed up. Thanks for pointing that out!

#86739
May 29, 2014 12:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.