1

I have a series of SharePoint applications, one being our Intranet site and one being a system for serviceinformation on our IT-systems (itstatus).

I really want to make a section of out intranet FrontPage dedicated to the latest serviceinformations.

I tried making a rest call to the site (itstatus) through a CEWP placed on the intranet FrontPage - but the REST call fails!

If I enter the REST URL in my browser it looks up the content just fine: http://itstatusshp.mysite.dk/_api/web/Lists/getByTitle('It-driftstatus')/items

Is there some kind of authentication that needs to be sent with the REST call for it to Work? My user has administration rights on both applications.

Thanks

  • 1
    You would be breaking SOP, but you can get through that with a proxy (or hacking the web.config on the target, then use CORS), but it happens that SharePoint apps have this built in, called web proxy - so my question is; do you have apps installed? – eirikb Apr 30 '15 at 5:52
  • No. No apps installed. But I have found the solution that I have to set up CORS for the application with the endpoint through PowerShell. – thewolf May 6 '15 at 7:53
  • do you mind sharing the solution? If it does not alter IIS (web.config or additional module or similar) I would love to see it. – eirikb May 6 '15 at 12:27
  • It is excactly altering the web.config – thewolf May 7 '15 at 7:40
  • ugh ​​​​​​​​​​​​​​​ – eirikb May 7 '15 at 8:19
1

So the solution is to run this PowerShell script on the web application providing the information:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0
$localFarm = Get-SPFarm
$webapp = Get-SPWebApplication "http://XXX---URL_OF_PROVIDING_WEBAPP---XXX"

# Remove old web.config modifications of MyAuthenticationProvider
$oldMods = @();
$webapp.WebConfigModifications | ? { $_.Owner -eq "CrossSiteScripting" } | % { 
$oldMods = $oldMods + $_
}

$oldMods | % { 
$webapp.WebConfigModifications.Remove($_) 
}

# update the Web Application and apply all existing web.config modifications - this executes the "remove" actions from above
$webapp.Update()
[Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplyWebConfigModifications()

#Wait until web.config modifications finished by timer job
while( (Get-SPTimerJob | ? { $_.Name -eq "job-webconfig-modification"}) -ne $null ) {
Write-Host "." -NoNewline
Start-Sleep 1
}

# New web.config modifications for MyAuthenticationProvider
$myModification1 = new-object   Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Allow-Origin' [@value='http://XXX---URL_OF_RECEIVING_WEBAPP---XXX']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"

#0 = for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Allow-Origin' value='http://XXX---URL_OF_RECEIVING_WEBAPP---XXX' />"
$webapp.WebConfigModifications.Add($myModification1)

$myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Request-Method'][@value='GET,POST,HEAD,OPTIONS']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Request-Method' value='GET,POST,HEAD,OPTIONS' />"
$webapp.WebConfigModifications.Add($myModification1)

$myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Request-Headers'][@value='Content-Type,Authorization']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Request-Headers' value='Content-Type,Authorization' />"
$webapp.WebConfigModifications.Add($myModification1)

$myModification1 = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$myModification1.Path = "configuration/system.webServer/httpProtocol/customHeaders"
$myModification1.Name = "add[@name='Access-Control-Allow-Credentials'][@value='true']"
$myModification1.Sequence = 0
$myModification1.Owner = "CrossSiteScripting"
$myModification1.Type = 0
$myModification1.Value = "<add name='Access-Control-Allow-Credentials' value='true' />"
$webapp.WebConfigModifications.Add($myModification1)

$webapp.Update()
#Wait until web.config modifications finished by timer job
while( (Get-SPTimerJob | ? { $_.Name -eq "job-webconfig-modification"}) -ne $null ) {
Write-Host "." -NoNewline
Start-Sleep 1
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.