检查用户是否可以访问SharePoint Online站点

时间:2018-02-28 11:52:43

标签: c# sharepoint sharepoint-online

我有以下代码:

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();
}

如果用户名和密码正确,一切正常。但有没有办法可以验证用户是否有权访问该网站(SharePoint Online)?

1 个答案:

答案 0 :(得分:0)