问题描述:

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...

网友答案:

I've used something like this:

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

HTH.

网友答案:

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?

相关阅读:
Top