Create user in another Membership.ApplicationName

梦想与她 提交于 2019-12-24 16:27:37

问题


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


回答1:


I've used something like this:

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

HTH.




回答2:


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?



来源:https://stackoverflow.com/questions/4368792/create-user-in-another-membership-applicationname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!