Bot在当地工作但不在天蓝色

时间:2018-05-18 07:52:30

标签: c# azure sharepoint botframework csom

我正在开发一个聊天机器人,可以帮助SharePoint内部部署网络的用户上传文件。机器人在本地工作但在Azure中测试时返回代码500。

我正在使用Csom库在站点树和SharePoint _api中导航以获取所有网站集。我做了一些测试,我不认为是导致这个错误的Csom,而是在Azure中不起作用的NetworkCredential。

我可以在Azure中使用凭证吗?

我知道问题来自这个功能

public void GetAllSiteCollections(string url)
    {

        HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(url + "/_api/search/query?querytext='contentclass:sts_site'&trimduplicates=false&rowlimit=100");

        endpointRequest.Method = "GET";
        endpointRequest.Accept = "application/json;odata=verbose";
        NetworkCredential cred = new NetworkCredential(Login, Mdp, DomaineUser);
        endpointRequest.Credentials = cred;
        HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();

        WebResponse webResponse = endpointRequest.GetResponse();
        Stream webStream = webResponse.GetResponseStream();
        StreamReader responseReader = new StreamReader(webStream);
        string response = responseReader.ReadToEnd();

        JObject jobj = JObject.Parse(response);

        for (int ind = 0; ind < jobj["d"]["query"]["PrimaryQueryResult"]["RelevantResults"]["Table"]["Rows"]["results"].Count(); ind++)
        {

            string urlCollection = jobj["d"]["query"]["PrimaryQueryResult"]["RelevantResults"]["Table"]["Rows"]["results"][ind]["Cells"]["results"][6]["Value"].ToString();
            string nomCollection = jobj["d"]["query"]["PrimaryQueryResult"]["RelevantResults"]["Table"]["Rows"]["results"][ind]["Cells"]["results"][3]["Value"].ToString();
            if (urlCollection.Contains("myLocalDomain/sites/") == true)
            {
                string[] split = urlCollection.Split('/');
                ClientCtx = new ClientContext(Domaine + "/sites/" + split[4]);
                using (ClientCtx = new ClientContext(ClientCtx.Url))
                {
                    ClientCtx.Credentials = new NetworkCredential(Login, Mdp, DomaineUser);
                    Web rootWeb = ClientCtx.Site.RootWeb;
                    ClientCtx.Load(rootWeb);

                    BasePermissions bp = new BasePermissions();
                    bp.Set(PermissionKind.AddListItems);

                    ClientResult<bool> viewListItems = rootWeb.DoesUserHavePermissions(bp);


                    ClientCtx.ExecuteQuery();
                    if (viewListItems.Value)
                    {
                        ListDesSiteCollections.Add(nomCollection, split[4]);
                    }

                }
            }
        }

        responseReader.Close();

    }

当我在http://botName.azurewebsites.net/api/messages检查日志时,我收到回复“请求的资源不支持http方法'GET'”

0 个答案:

没有答案