WebRequest到提供程序托管的加载项中的自定义页面 [英] WebRequest to custom page in provider-hosted add-in

查看:52
本文介绍了WebRequest到提供程序托管的加载项中的自定义页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个提供者托管的加载项,其中包括一些自定义Web表单页面和远程事件接收器。主机是SharePoint Online,应用程序位于Azure中。 在一个RER中,它在列表的ItemUpdated上异步触发,我正在尝试为其中一个自定义页面创建一个WebRequest
,以便以特定格式保存响应。 根据Microsoft示例,该页面在pre-init上具有此代码:

I'm developing a provider-hosted add-in which includes some custom web form pages and remote event receivers. Host is SharePoint Online and App is in Azure.  In one RER, which fires asynchronously on ItemUpdated of a list, I'm trying to create a WebRequest to one of the custom pages to save the response in a particular format.  The page has this code on pre-init as per Microsoft examples:

protected void Page_PreInit(object sender, EventArgs e)
          {
              Uri redirectUrl;
              switch (SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl))
              {
                  case RedirectionStatus.Ok:
                      return;
                  case RedirectionStatus.ShouldRedirect:
                      Response.Redirect(redirectUrl.AbsoluteUri, endResponse: true);
                      break;
                  case RedirectionStatus.CanNotRedirect:
                      Response.Write("An error occurred while processing your request.");
                      Response.End();
                      break;
              }
          }




$


如果我只是做一个这样的基本要求:




If I just do a basic request like this:

var url = "https://myname.azurewebsites.net/Pages/MyCustomPage.aspx?standardquerystringstuff";
HttpWebRequest pRequest = (HttpWebRequest)WebRequest.Create(redirectUrlString);
pRequest.UseDefaultCredentials = true;
pRequest.Method = "GET";
pRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)";
WebResponse response = pRequest.GetResponse();




页面中的CheckRedirectionStatus返回RedirectionStatus.ShouldRedirect,其中uri指向https:// hostweb / _layouts / 15 / AppRedirect.aspx CLIENT_ID = XXX&安培; REDIRECT_URI = pathtomycustompage群组。在响应对象中,responseUri指向https://login.microsoftonline.com/some-guid/oauth2/authorize?client_id ...
$


在我花钱之前更多的时间调查这个,是否有可能做我想要的事情?



提前谢谢。


The CheckRedirectionStatus in the page returns RedirectionStatus.ShouldRedirect with a uri pointing to https://hostweb/_layouts/15/AppRedirect.aspx?client_id=xxx&redirect_uri=pathtomycustompage.  In the response object, the responseUri points to https://login.microsoftonline.com/some-guid/oauth2/authorize?client_id...

Before I spend much more time looking into this, should it be possible to do what I'm after?

Thanks in advance.

推荐答案

您好,

以下代码供您参考,请在HttpWebRequest的Authorization标题中添加访问令牌。

The following code for your reference, please add Access Token in Authorization header in HttpWebRequest.

var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
HttpWebRequest listRequest = (HttpWebRequest)HttpWebRequest.Create(spContext.SPAppWebUrl + "/_api/web/lists");
listRequest.Method = "GET";
listRequest.Accept = "application/atom+xml";
listRequest.ContentType = "application/atom+xml;type=entry";
listRequest.Headers.Add("Authorization", "Bearer " + spContext.UserAccessTokenForSPAppWeb);

更多信息请点击此处:

https://dannyjessee.com/blog/index.php/2014/07/accessing-sharepoint-data-from-provider-hosted-apps-use-the-right-context/

https://docs.microsoft.com/en-us/sharepoint/dev/sp-插件/创建-A-供应商提供托管,加载,但─包括-A-定制的SharePoint列表和小故事#先决条件,为创造 - 这-SharePoint的附加 < a href ="https://dannyjessee.com/blog/index.php/2014/07/accessing-sharepoint-data-from-provider-hosted-apps-use-the-right-context/">

最好的问候,

Dennis


这篇关于WebRequest到提供程序托管的加载项中的自定义页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆