c# - 使用客户端对象模型的 Sharepoint 2010 用户身份验证(Windows 凭据)

标签 c# authentication sharepoint ntlm sharepoint-clientobject

我正在尝试登录使用 Windows 集成 (NTLM) 身份验证的 SharePoint 网站。有两种方法可以输入 SharePoint 网站的凭据:Windows 身份验证和表单例份验证。

但是,此特定网站上禁用了表单例份验证,我只能使用 Windows 身份验证。 有没有办法让我使用与登录 Windows 计算机时不同的凭据登录此网站?

请参阅此处的错误:Form authentication denied

        String site = "http://sharepoint/";
        ClientContext context = new ClientContext(site);
        context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
        FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");
        context.FormsAuthenticationLoginInfo = formsAuthInfo;

        // The SharePoint web at the URL.
        Web web = context.Web;

        // We want to retrieve the web's properties.
        context.Load(web);

        // Execute the query to the server.
        context.ExecuteQuery();


        InitializeComponent();

我也尝试过使用: context.Credentials = new NetworkCredential("用户", "通行证", 站点);

       ClientContext context = new ClientContext(site);
       context.Credentials = new NetworkCredential("user", "pass", site);


        // The SharePoint web at the URL.
        Web web = context.Web;

        // We want to retrieve the web's properties.
        context.Load(web);

        // Execute the query to the server.
        context.ExecuteQuery();


        InitializeComponent();

我收到以下 401(未经授权)error

最佳答案

不要将 ClientContext 对象的 AuthenticationMode 属性更改为 FormsAuthentication,而是尝试设置该对象的 Credentials属性到有效的网络凭据对象。

ClientContext context = new ClientContext("http://sharepointsite/");
context.Credentials = new NetworkCredential("username","password","domain");

关于c# - 使用客户端对象模型的 Sharepoint 2010 用户身份验证(Windows 凭据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34773547/

相关文章:

c# - Azure:如何创建对内部端点的服务引用

authentication - 像Spring Security这样的GWT用户身份验证?

java - 我如何使用条件登录并将列表转换为 JSON 格式

javascript - 为oauth创建一个弹出窗口

sharepoint - 弹出窗口输入凭据

azure - 如何使用 Graph api 从 SharePoint 列表中临时删除项目

c# - 将 RTF 格式转换为 HTML 标签

c# - JArray.Remove(JToken) 不删除

sharepoint - 从 Sharepoint 站点删除规范链接

c# - 使用 Shift+F5 终止运行后返回编码 Pane 的 Visual Studio 快捷方式