【问题标题】:Sharepoint 2010 User Authentication (windows Credential) with Client Object Model带有客户端对象模型的 Sharepoint 2010 用户身份验证(Windows 凭据)
【发布时间】:2016-04-18 19:58:18
【问题描述】:

我正在尝试登录到使用 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("user", "pass", site);

       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

【问题讨论】:

  • 到目前为止,您还没有提供任何您尝试过的代码。您在寻找非代码解决方案吗?在 Windows 7 中,您可以使用与登录时不同的 Windows 凭据运行应用程序,方法是按住 Shift 并右键单击可执行文件,然后选择“以不同用户身份运行”
  • 您好,感谢您的评论。我已经包含了我的代码。另外,我运行的是 windows server 2008 R2 Standard,而不是 windows 7。

标签: c# authentication sharepoint ntlm sharepoint-clientobject


【解决方案1】:

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

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

【讨论】:

  • 我试过了,现在我得到 401(未经授权的错误)。我更新了我上面的帖子
  • 嗨@TaimoorRana,NetworkCredential 构造函数的第三个参数应该是包含帐户的Active Directory 域前缀的字符串值。例如,如果您的登录名是“MSFT\RanaTaimoor”,则用户名是“RanaTaimoor”,域是“MSFT”
  • 我的用户名如下所示:ab12345 -(抱歉,我不能分享确切的用户名,因为它是公司帐户)
  • 所以“ab”将是我的域,“12345”将是我的用户名。所以我使用了: context.Credentials = new NetworkCredential("ab12345","password","sharepointsite/"); 我仍然得到相同的 401 错误
  • 试试context.Credentials = new NetworkCredential("12345","password","ab")
【解决方案2】:

不知道是否迟到,但默认情况下,托管客户端对象模型使用用户的 Windows 凭据 (DefaultCredentials) 对用户进行身份验证。

因此您无需显式设置凭据。只需设置以下 -

context.AuthenticationMode = ClientAuthenticationMode.Default;

【讨论】:

    猜你喜欢
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多