Home:ALL Converter>Adding users programmaticaly on a SharePoint 2010 claims based site (extranet zone)

Adding users programmaticaly on a SharePoint 2010 claims based site (extranet zone)

Ask Time:2012-09-22T03:40:47         Author:Prakash

Json Formatter

I have a SharePoint 2010 site which has Zone Level security. The site has Windows Authentication in Default Zone while it has Claimed Based Authentication in Extranet Zone. A membership provider is used for Claimed Based site.

My my requirement is to add user of that membership provider to this claimed based site programmatically (c#).

Any help will be greatly appreciated.

Thanks

Author:Prakash,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12537147/adding-users-programmaticaly-on-a-sharepoint-2010-claims-based-site-extranet-zo
Dipesh Bhanani :

For adding claim users, you need to create a pattern as:\n\ni:0#.f|{MembershipProvider}|{UserName}\n\n\nI hope the below code gives you enough details to resolve your issue:\n\nstring userName = \"dipesh\";\nstring membershipProvider = \"MyCustomMP\";\nstring claimUser = string.Format(\"i:0#.f|{0}|{1}\", membershipProvider, userName);\nSPUser user = web.EnsureUser(claimUser);\n",
2012-09-30T09:46:04
yy