【问题标题】:c# script Sharepoint API giving 401 Error on remote serverc#脚本Sharepoint API在远程服务器上给出401错误
【发布时间】:2019-04-30 02:49:30
【问题描述】:

我正在使用以下代码进行共享点身份验证。它在本地机器上工作得很好,但是当我在服务器上部署这个包时,它给出了 401 错误。

class Program
{

    static void Main(string[] args)
    {
        //Delcaring Required variable (Actual variable values have been changed to dummy one)
        var webUri = new Uri("https://blahblah.sharepoint.com");  
        string proxy = "http://abc.abc.com:1234/";
        const string userName = "abc@blahblah.com";
        const string password = "123";
        string SalesPOV_GUID = "6319bd1f-7f-4ffd-95dc-a992afc4da10";
        string Clients_GUID = "ojfoeiawe-3abcc6-41cd-be23-cf6043671d53";

        //Creating a secured sring for SharepointOnline Credentials
        var securePassword = new SecureString();
        foreach (var c in password)
        {
            securePassword.AppendChar(c);
        }

        //Setting up credentials for Sharepoint
        var credentials = new SharePointOnlineCredentials(userName, securePassword);

        //Makiing a Call
        using (var client = new WebClient())
        {


            try
            {
                //setting up proxy
                System.Net.WebProxy wp = new System.Net.WebProxy();
                Uri newUri = new Uri(proxy);
                wp.Address = newUri;
                client.Proxy = wp;
            }
            catch (WebException e) //In package we need to fail the package on catching exception.
            {
                string pageContent = new StreamReader(e.Response.GetResponseStream()).ReadToEnd().ToString();
            }
            client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
            client.Credentials = credentials;
        }
    }
}

【问题讨论】:

    标签: c# web sharepoint sharepoint-rest-api


    【解决方案1】:

    检查您的共享点网站是否设置为物理路径的“直通”身份验证。

    【讨论】:

    • 您能解释一下为什么我们需要设置透传身份验证吗?
    • 在 IIS 网站中指定用户进行物理路径访问,sharepoint 将无法获取您通过网络发送的凭据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 2011-01-03
    • 1970-01-01
    相关资源
    最近更新 更多