1

I have an administration website - the users of which should be able to modify users for a public site. This means the administration site has a valid membership provider, but I want to be able to access/change members in another site (and therefore ApplicationName).

First thought was to set ApplicationName on the Membership static - but that seems like a bad idea according to answers here: Changing Membership.ApplicationName in code - thread safety.

Second thought was to duplicate the MembershipProvider entry to the web.config - so now I can do WebSiteMembershipProvider = Membership.Providers("WebsiteSqlMembershipProvider") - but I can't now seem to get to a 'Membership' object which will let me (for example) call the standard 'CreateUser' method.

I tried WebSiteMembershipProvider.CreateUser - but it takes a load more parameters, and doesn't seem to do anything if I poke some values into it.

Am I nearly there? Or do I need a different approach? There's always the SqlProvider's stored procedures, I suppose...

Community
  • 1
  • 1
Ian Grainger
  • 5,148
  • 3
  • 46
  • 72

2 Answers2

1

I've used something like this:

var _provider = Membership.Providers["WebsiteSqlMembershipProvider"];
_provider.CreateUser(userName, password, email, null, null, true, null, out status);

HTH.

CGK
  • 2,662
  • 21
  • 24
  • and @Greg - Glad to see my approach was correct - and the problem seemed to be simply that there's an empty string check for password question and answer. "" doesn't work but null does. I'll accept this answer as it was first. I should've experimented some more before I asked, really! – Ian Grainger Dec 07 '10 at 09:16
  • Nice to know that `null` works, had the same problem back then. You can take a look at how Authorization is implemented in the default MVC template to get some ideas on how to handle errors, and use the `status` variable to give feedback to the user in case something happens (ie. password not conforming to minimum length or regex rules defined in the provider configuration). – CGK Dec 07 '10 at 11:22
0

but it takes a load more parameters

Pass in nulls

MembershipCreateStatus status; 
MembershipUser u = CreateUser(username, password, email,null,null,true, out status);

and doesn't seem to do anything if I poke some values into it.

It should. Could you post the relevant web.config section?

Greg
  • 16,540
  • 9
  • 51
  • 97