none
ensure user in sharepoint 2010 for fba user RRS feed

  • Question

  • Hi all,

    I want to validate the fba user uisng below code.Login name is having prefix like  i:0#.f|provider|sretre.But iam getting null exception.Please help how to validate.

    public static string IsSharePointUser(string siteURL,string userName)
    {
    string flag="";
    try
    {
    ClientContext ctx = new ClientContext(siteURL);
    Web rootWeb = ctx.Site.RootWeb;
    User usr = rootWeb.EnsureUser(userName);
    ctx.Load(usr);
    ctx.ExecuteQuery();
    flag = usr.LoginName;
    }
    catch
    {
    flag = "";

    return flag;
    }

    Thanks

    Friday, January 18, 2019 4:36 AM

All replies

  • Hi

    I found a similar link for you and hope it can help you more or less.

    https://stackoverflow.com/questions/21401391/encoded-login-names-in-sharepoint-client-object-model

    The EnsureUser method expect an "encoded" login name.


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    Friday, January 18, 2019 9:10 AM
  • i have passed the encodedname but no luck.Please help.
    Friday, January 18, 2019 12:21 PM
  • Hi,

    If you only want to return the user login name, the following code for your reference.

    public static string IsSharePointUser(string siteURL,string userName)
    {
    	string flag="";
    	try
    	{
    		ClientContext ctx = new ClientContext(siteURL);
    		var info = Utility.ResolvePrincipal(ctx, ctx.Web, userName, PrincipalType.All, PrincipalSource.All, null, false);
                    ctx.ExecuteQuery();
    		if (info.Value.PrincipalType == PrincipalType.User)
    		{
    			flag = info.Value.LoginName;
    		}	
    	}
    	catch
    	{
    		flag = "";
    	} 
    	return flag;
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Monday, January 21, 2019 7:01 AM
    Moderator
  • Hi,

    Would you please provide us with an update on the status of your issue?

    Best Regards,
    Dennis

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, January 28, 2019 8:16 AM
    Moderator