简体   繁体   中英

Check if user has access to SharePoint Online site

I have the code below:

using (var context = new ClientContext(URL))
{
    context.Credentials = new SharePointOnlineCredentials(username, password);

    Web web = context.Web;
    context.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id));
    context.ExecuteQuery();

    List SupportList = context.Web.Lists.GetByTitle("Support");

    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
    ListItem newItem = SupportList.AddItem(itemCreateInfo);

    foreach (var selector in f.rtxt_select.Text.Split(','))
    {
        var s = selector.Split('=');
        newItem[s[0].Trim()] = m.GetType().GetProperty(s[1].Trim()).GetValue(m, null);
    }

    newItem.Update();

    context.ExecuteQuery();
    f.txtMessage.AppendText("Message has been added to Sharepoint List \n ");
    f.lbl_successCount.Text = (Convert.ToInt32(f.lbl_successCount.Text) + 1).ToString();
}

Everything works just fine if the username and password is correct. But Is there is a way i can validate if the user has access to the site( SharePoint Online )?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM