首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Sharepoint Online中激活/安装解决方案(Sitecollection -> Webtemplate模板)

在Sharepoint Online中激活/安装解决方案(Sitecollection -> Webtemplate模板)
EN

Stack Overflow用户
提问于 2015-11-09 22:02:10
回答 1查看 160关注 0票数 0

我试着在Webrequest的帮助下,用Sharepoint Online中的按钮来触发。

第一个错误代码:

使用"0“参数调用"GetResponse”时出现异常:“远程服务器返回错误:(403)已禁用。”

代码语言:javascript
复制
$solutionId = Get-SPOSolutionId -solutionName $solutionName

# Queries the solution's page
$operation = ""
if($activate) 
{ 
    $operation = "ACT" 
} 
else 
{ 
    $operation = "DEA" 
}

$solutionPageUrl = Join-SPOParts -Separator '/' -Parts $context.Site.Url, "/_catalogs/solutions/forms/activate.aspx?Op=$operation&ID=$solutionId"

$c
if ($context.Credentials -ne $null)
{
    $authCookieValue = $context.Credentials.GetAuthenticationCookie($context.Url)
    # Create fed auth Cookie
    $fedAuth = new-object System.Net.Cookie
    $fedAuth.Name = "FedAuth"
    $fedAuth.Value = $authCookieValue.TrimStart("SPOIDCRL=")
    $fedAuth.Path = "/"
    $fedAuth.Secure = $true
    $fedAuth.HttpOnly = $true
    $fedAuth.Domain = (New-Object System.Uri($context.Url)).Host

    # Hookup authentication cookie to request
    $cookieContainer.Add($fedAuth)

    $request.CookieContainer = $cookieContainer
}
else
{
    # No specific authentication required
    $request.UseDefaultCredentials = $true
}

$request.ContentLength = 0

$response = $request.GetResponse()

    # decode response
    $strResponse = $null
    $stream = $response.GetResponseStream()
    if (-not([String]::IsNullOrEmpty($response.Headers["Content-Encoding"])))
    {
        if ($response.Headers["Content-Encoding"].ToLower().Contains("gzip"))
        {
            $stream = New-Object System.IO.Compression.GZipStream($stream, [System.IO.Compression.CompressionMode]::Decompress)
        }
        elseif ($response.Headers["Content-Encoding"].ToLower().Contains("deflate"))
        {
            $stream = new-Object System.IO.Compression.DeflateStream($stream, [System.IO.Compression.CompressionMode]::Decompress)
        }
    }

    # get response string
    $sr = New-Object System.IO.StreamReader($stream)

        $strResponse = $sr.ReadToEnd()

    $sr.Close()
    $sr.Dispose()

    $stream.Close()

    $inputMatches = $strResponse | Select-String -AllMatches -Pattern "<input.+?\/??>" | select -Expand Matches

    $inputs = @{}

    # Look for inputs and add them to the dictionary for postback values
    foreach ($match in $inputMatches)
    {
        if (-not($match[0] -imatch "name=\""(.+?)\"""))
        {
            continue
        }
        $name = $matches[1]

        if(-not($match[0] -imatch "value=\""(.+?)\"""))
        {
            continue
        }
        $value = $matches[1]

        $inputs.Add($name, $value)
    }

    # Lookup for activate button's id
    $searchString = ""
    if ($activate) 
    {
        $searchString = "ActivateSolutionItem"
    }
    else
    {
        $searchString = "DeactivateSolutionItem"
    }

    $match = $strResponse -imatch "__doPostBack\(\&\#39\;(.*?$searchString)\&\#39\;"
    $inputs.Add("__EVENTTARGET", $Matches[1])

$response.Close()
$response.Dispose()

# Format inputs as postback data string, but ignore the one that ends with iidIOGoBack
$strPost = ""
foreach ($inputKey in $inputs.Keys)
{
    if (-not([String]::IsNullOrEmpty($inputKey)) -and -not($inputKey.EndsWith("iidIOGoBack")))
    {
        $strPost += [System.Uri]::EscapeDataString($inputKey) + "=" + [System.Uri]::EscapeDataString($inputs[$inputKey]) + "&"
    }
}
$strPost = $strPost.TrimEnd("&")

$postData = [System.Text.Encoding]::UTF8.GetBytes($strPost);

# Build postback request
$activateRequest = $context.WebRequestExecutorFactory.CreateWebRequestExecutor($context, $solutionPageUrl).WebRequest
$activateRequest.Method = "POST"
$activateRequest.Accept = "text/html, application/xhtml+xml, */*"
if ($context.Credentials -ne $null)
{
    $activateRequest.CookieContainer = $cookieContainer
}
else
{
    # No specific authentication required
    $activateRequest.UseDefaultCredentials = $true
}
$activateRequest.ContentType = "application/x-www-form-urlencoded"
$activateRequest.ContentLength = $postData.Length
$activateRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
$activateRequest.Headers["Cache-Control"] = "no-cache";
$activateRequest.Headers["Accept-Encoding"] = "gzip, deflate";
$activateRequest.Headers["Accept-Language"] = "fr-FR,en-US";

# Add postback data to the request stream
$stream = $activateRequest.GetRequestStream()
    $stream.Write($postData, 0, $postData.Length)
    $stream.Close();
$stream.Dispose()

# Perform the postback
$response = $activateRequest.GetResponse()
$response.Close()
$response.Dispose()

上下文

代码语言:javascript
复制
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($xmlContent.sites.site.Url) 

$context.Credentials = $spoCredentials
$context.RequestTimeOut = 500 * 60 * 10;
$web = $context.Web
$site = $context.Site   
$context.Load($web)
$context.Load($site)
try
{
$context.ExecuteQuery()

$spoCredentials

代码语言:javascript
复制
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($xmlContent.sites.site.Username, $SecurePassword)
EN

回答 1

Stack Overflow用户

发布于 2015-11-09 23:11:48

是否已在清单文件中添加了外部终结点。您需要添加终结点的url,以便应用程序具有访问外部终结点的权限。

以下是如何执行/查询外部终结点和其他源的代码示例链接,例如:网络应用程序、主机应用程序或站点collections...etc。

http://blog.ctp.com/2014/06/23/data-access-in-sharepoint-hosted-apps/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33610851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档