GVKun编程网logo

从 Sharepoint online 中的 SPFX 导航到新网址

8

如果您对从Sharepointonline中的SPFX导航到新网址感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解从Sharepointonline中的SPFX导航到新网址的各种细节,此外还有关

如果您对从 Sharepoint online 中的 SPFX 导航到新网址感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解从 Sharepoint online 中的 SPFX 导航到新网址的各种细节,此外还有关于asp.net-mvc-5 – Sharepoint 2013 MVC 5提供商托管的应用程序.无法使用[SharePointContextFilter]在HttpPost上进行身份验证、c# – SharePoint Online身份验证失败、CamlQuery对SharePointOnline List 发起查询请求、ID文档,ID文件夹SharePoint-Online的实用技巧。

本文目录一览:

从 Sharepoint online 中的 SPFX 导航到新网址

从 Sharepoint online 中的 SPFX 导航到新网址

您可以创建元素 'a' 并调用 click to open url

let a = document.createElement('a');
a.href = 'your link to open';
a.click();

这很好用。

您也可以使用 react-router,如描述 here

还有重定向链接:

import { Redirect } from 'react-router';

当你需要重定向到 som url 时,你呈现重定向:

<Redirect to={'/to url'}></Redirect>
,

我在没有框架 SPFX 的情况下进行测试。

测试结果: enter image description here 测试代码供大家参考:

public render(): void {

    this.domElement.innerHTML = `
      <div>
        <div>
          <div>
            <div>
              <span>Welcome to SharePoint!</span>
              <p>Customize SharePoint experiences using Web Parts.</p>
              <p>${escape(this.properties.description)}</p>
              <a href="https://aka.ms/spfx">
                <span>Learn more</span>
              </a>
              <select id="option" >
                <option value="test1">test1</option>
                <option value="test2">test2</option>
                <option value="test3">test3</option>
              </select>

            </div>
          </div>
        </div>
        
        </div>`;
        this.domElement.querySelector('#option').addEventListener('change',(e) => { 
          window.location.href="https://www.google.com/search?q="+e.target["value"]
          
        })
        
    
    
  }

asp.net-mvc-5 – Sharepoint 2013 MVC 5提供商托管的应用程序.无法使用[SharePointContextFilter]在HttpPost上进行身份验证

asp.net-mvc-5 – Sharepoint 2013 MVC 5提供商托管的应用程序.无法使用[SharePointContextFilter]在HttpPost上进行身份验证

过去一周我一直在敲打我的头脑,无法解决针对sharepoint提供商托管应用程序的正确身份验证的一些问题.

我目前正在为公司的Sharepoint在线开发一个sharepoint应用程序.我正在使用Visual Studio 2013.我将该应用程序部署为公司的Windows Azure门户上的云服务.一切顺利到我需要制作HttpPost的时候,然后应用程序无法进行身份验证. Conroller的设计如下:

[SharePointContextFilter]
    public ActionResult Index()
    {
        UserSingleton user_temp = UserSingleton.GetInstance();

        User spUser = null;

        SharePointContext spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

        using (var clientContext = spContext.createuserClientContextForSPHost())
        {
            if (clientContext != null)
            {
                spUser = clientContext.Web.CurrentUser;

                clientContext.Load(spUser,user => user.Title,user => user.Email);

                clientContext.ExecuteQuery();

                ....code....

            }
        }

           ....code....

        return View();
    }

加载索引页面很顺利,操作会创建用户上下文,这一切都很好.当我尝试提交HttpPost时问题就出现了:

[HttpPost]
    [ValidateAntiForgeryToken]
    [SharePointContextFilter]
    public ActionResult GetService(System.Web.Mvc.FormCollection fc)
    {
        PlannedHours ph = this.PopulateModel(fc);

        if (ph == null)
            return View("NoInfoFound");

        ViewData["PlannedHours"] = ph;

        return View("Index");
    }

当我通过帖子按钮拨打此电话时,我收到“无法确定您的身份.请通过启动您网站上安装的应用再试一次.” Shared / Error.cshtml视图.问题是当我删除[SharePointContextFilter]然后它工作,但这意味着请求不通过[SharePointContextFilter]因此它没有正确认证?或者是吗?因为它无法验证用户的合法性.

当我不删除[SharePointContextFilter]并调用帖子时,我注意到的一件事情,那么网址最终没有{StandardTokens}查询.是假设是这样的 – 我的意思是它像hostname.com/Home/GetService一样,但是当我使用actionlink时,spcontext.js总是将{StandardTokens}查询附加到基本URL – 像hostname.com/Home一样/ ActionNAme / SPHostUrl = HTTPS:// SHAREPOINTPAGEURL ….

我注意到的是,我调用hostname.com/Home/ActionNAme/而没有附加无法传递[SharePointContextFilter]的查询.

我是sharepoint 2013和MVC 5(Razor)的新手,所以如果你知道为什么我的HttpPost无法通过[SharePointContextFilter]尝试解释我或给出任何建议.我尝试过使用HttpGet但是,当我调用具有[SharePointContextFilter]的HttpGet并附加SPHostUrl =令牌时,它可以工作.但后来我无法使用[ValidateAntiForgeryToken].甚至在这样的应用程序中是否需要[ValidateAntiForgeryToken],因为[SharePointContextFilter]总是检查用户的合法性?我现在很困惑.网上有大量的资料可供阅读,没有什么可以解释何时附加这些标准代币,什么时候使用[SharePointContextFilter]等.事实上我第一次在我的网站上开发一个sharepoint应用程序.生活和我一直在研究和编码过去3周.所以我的知识还很有限,在回答时要记住这一点.在此先感谢,我希望我得到一些关于正在发生的事情的澄清!

—————————– UPDATE ——————– ——————–

好的,快速更新.我发现了一些相当奇怪的东西. SharePointContextFilterattribute.cs

public class SharePointContextFilterattribute : ActionFilterattribute
    {
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (filterContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }

        Uri redirectUrl;
        switch (SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext,out redirectUrl))
        {
            case RedirectionStatus.Ok:
                return;
            case RedirectionStatus.ShouldRedirect:
                filterContext.Result = new RedirectResult(redirectUrl.AbsoluteUri);
                break;
            case RedirectionStatus.CanNotRedirect:
                filterContext.Result = new ViewResult { ViewName = "Error" };
                break;
        }
    }
}

始终返回最后一个案例(RedirectionStatus.CanNotRedirect),因为方法SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext,out redirectUrl)包含一些我无法解决的问题.

首先:

Uri spHostUrl = SharePointContext.GetSPHostUrl(httpContext.Request);

        if (spHostUrl == null)
        {
            return RedirectionStatus.CanNotRedirect;
        }

好吧我理解 – 如果httpContext.Request不包含spHostUrl它将无法重定向.出于某种原因必须存在.

但是以下内容:

if (StringComparer.OrdinalIgnoreCase.Equals(httpContext.Request.HttpMethod,"POST"))
        {
            return RedirectionStatus.CanNotRedirect;
        }

等WHAAAT?!?不允许POST?!!?这里发生了什么?我真的不知道我做错了什么或什么?我甚至可以使用SharePointContext.cs吗?我真的需要有人来澄清到底发生了什么…我很感激!

解决方法

以上解决方案对我不起作用.我的帖子有同样的问题,但对我来说就是这个问题
return RedirectToAction("Index");

导致错误.

我改成了:

return RedirectToAction("Index",new {SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri});

它起作用了.

我不确定这是你的问题的解决方案,因为你正在做返回视图,但它可能有助于某人:)

c# – SharePoint Online身份验证失败

c# – SharePoint Online身份验证失败

我有一个C#应用程序,它使用Web请求对SharePoint Online进行身份验证.它适用于我,但其他人收到以下错误:

<?xml version="1.0" encoding="utf-8" ?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault">
  <S:Body>
    <S:Fault>
      <S:Code>
        <S:Value>S:Sender</S:Value>
        <S:Subcode>
          <S:Value>wst:FailedAuthentication</S:Value>
        </S:Subcode>
      </S:Code>
      <S:Reason>
        <S:Text xml:lang="en-US">Authentication Failure</S:Text>
      </S:Reason>
      <S:Detail>
        <psf:error>
          <psf:value>0x80048821</psf:value>
          <psf:internalerror>
            <psf:code>0x80041034</psf:code>
            <psf:text>The specified member name is either invalid or empty.&#x000D;&#x000A;</psf:text>
          </psf:internalerror>
        </psf:error>
      </S:Detail>
    </S:Fault>
  </S:Body>
</S:Envelope>

这个错误是什么意思?我很确定他们输入了正确的用户名和密码.是否有一个SharePoint Online错误代码列表,我可以找到哪些地方可以帮助我识别问题?

这是我的C#代码:

var request = (HttpWebRequest)WebRequest.Create(@"https://login.microsoftonline.com/extSTS.srf");
request.AllowAutoRedirect = false;
request.ContentType = @"application/json; odata=verbose";
request.CookieContainer = this.CookieContainer;
request.Method = @"POST";
request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";

string soapRequest = Strings.SharePointOnlineAuthenticationRequest
    .Replace(@"$(UserName)",this.UserName)
    .Replace(@"$(Password)",this.Password)
    .Replace(@"$(Address)",this.SiteUrl);
byte[] contentBytes = new ASCIIEncoding().GetBytes(soapRequest);
request.ContentLength = contentBytes.Length;
using (var requestStream = request.GetRequestStream())
{
    requestStream.Write(contentBytes,contentBytes.Length);
}

Strings.SharePointOnlineAuthenticationRequest

这是我发送的SOAP请求. “$(UserName)”,“$(密码)”和“$(地址)”标记在运行时被替换.

<value>
  <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
  <a:Action s:mustUnderstand="1=">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
  <a:ReplyTo>
  <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
  </a:ReplyTo>
  <a:To s:mustUnderstand="1=">https://login.microsoftonline.com/extSTS.srf</a:To>
  <o:Security s:mustUnderstand="1=" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
  <o:Usernametoken>
  <o:Username>$(UserName)</o:Username>
  <o:Password>$(Password)</o:Password>
  </o:Usernametoken>
  </o:Security>
  </s:Header>
  <s:Body>
  <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
  <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
  <a:EndpointReference>
  <a:Address>$(Address)</a:Address>
  </a:EndpointReference>
  </wsp:AppliesTo>
  <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/noproofKey</t:KeyType>
  <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
  <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
  </t:RequestSecurityToken>
  </s:Body>
  </s:Envelope>
</value>

解决方法

最近是否更改了用户名,我发现名称更改后缺少ADFS声明的问题: see techet article AD FS 2.0: Claims Are Missing From The Output Claim Set After A User’s Name Has Changed

CamlQuery对SharePointOnline List 发起查询请求

CamlQuery对SharePointOnline List 发起查询请求

最近的项目中遇到了一个需求,需要向SharePointList 查询Item是否存在,找到了CamlQuery这样一个方法,但是没有找到使用这个接口的频率限制说明文档,于是就有了这篇随笔。

新接触这个方向,请大家多多指教。

 

#Load SharePoint CSOM Assemblies
	Add-Type -Path "F:\Microsoft.SharePoint.Client.dll"
	Add-Type -Path "F:\Microsoft.SharePoint.Client.Runtime.dll"
	Add-Type -Path "F:\Microsoft.SharePoint.Client.Publishing.dll"
	#Variables for Processing
	$SiteUrl = "<app web url>"
	$ListName="<ListTitle>"
	 
	$UserName="<account>"
	$Password ="<password>"
	  
	#Setup Credentials to connect
	$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
	  
	#Set up the context
	$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
	$Context.Credentials = $credentials

	
	$List = $Context.web.Lists.GetByTitle(''<ListTitle>'')

	$Title="Test"
	$start = Get-Date
	for($i=0;$i -le 1000;$i++)
	{
		try 
		{     
		
		$Query = New-Object Microsoft.SharePoint.Client.CamlQuery;
		$Query.ViewXml = "<View><Query><Where><Eq><FieldRef Name=''Title'' /><Value Type=''Text''>"+$Title+"</Value></Eq></Where></Query></View>"
		$ListItems = $list.GetItems($Query);
		$Context.Load($ListItems)
		$Context.ExecuteQuery()
		$midend = Get-Date
		write-host "Test"+$i+"Do"+($midend - $start).TotalSeconds

		"Test"+$i+"Do"+($midend - $start).TotalSeconds | Out-File -Append d:\PsTest.txt
		} 
		catch [System.Exception] 
		{ 
		$midend = Get-Date
		# write-host "Test"$i "Error" ($midend - $start).TotalSeconds
		"Test"+$i+"Error"+($midend - $start).TotalSeconds | Out-File -Append d:\PsTest.txt
        write-host -f red $_.Exception.ToString()    
		}     
	}
		$end = Get-Date
		write-host "Test"$i "Console"($end - $start).TotalSeconds
		"Test"+$i+"Console"+($end - $start).TotalSeconds| Out-File -Append d:\PsTest.txt

  根据返回的结果统计来看,1000次顺序Query请求成功率为100%,曲线如下

1000次的Query查询大概用时238.46秒,曲线中纵轴为响应的返回时间,整体看来曲线还不错,回来进行一下并行测试的的情况。

 

ID文档,ID文件夹SharePoint-Online

ID文档,ID文件夹SharePoint-Online

无法为其文档分配其父文件夹的ID。文件夹和文档都是SharePoint库中的项目。无论您创建文件夹还是文档,它都会占用一个ID占位符。 ID是自动增加的,无法分配。

因此,除了修改SharePoint DB的内容外,我认为我们无法操作其ID。可能的解决方法是,我们定义一个自定义列并将其视为ID字段。

我们今天的关于从 Sharepoint online 中的 SPFX 导航到新网址的分享已经告一段落,感谢您的关注,如果您想了解更多关于asp.net-mvc-5 – Sharepoint 2013 MVC 5提供商托管的应用程序.无法使用[SharePointContextFilter]在HttpPost上进行身份验证、c# – SharePoint Online身份验证失败、CamlQuery对SharePointOnline List 发起查询请求、ID文档,ID文件夹SharePoint-Online的相关信息,请在本站查询。

本文标签: