Home > Microsoft SharePoint, Microsoft SharePoint 2010, MOSS2007, SharePoint2013, Angular JS > SharePoint: Access denied error while calling web service from JavaScript

SharePoint: Access denied error while calling web service from JavaScript

Hi Friends,

I would like to share one very specific while calling web service from JavaScript, we were getting exception. Important point to note here is the code is working very fine if we access the page on server. But we are getting JavaScript ‘Error: Access is denied.’ Error while accessing the web page from client machine through browser.

error1

We are getting exception where we are calling the web service.

After some analysis the error came out as HTTP and HTTPS mixed content issue.

In our case HTTPS is configured on load balancer level and on ISS 7 level we have HTTP only hence web service call is working fine.

While accessing from outside URL is getting accessed only with HTTPS and non-secured request is also redirected with secured.

Problem fund that we have used ‘_spPageContextInfo.webAbsoluteUrl’ variable which is providing the HTTP path as SharePoint is unaware with existence of HTTPS as it is configured on load balancer level.

‘_spPageContextInfo.webAbsoluteUrl’ is supposed to give HTTPS path if HTTPS configured on ISS 7 level but as in our case SSL is configured on load balancer hence SharePoint is unaware about SSL.

Solution:

We have checked the protocol of the browser request using ‘document.location.protocol’ and if it is HTTPS then we replaced HTTP with HTTPS from the output of ‘_spPageContextInfo.webAbsoluteUrl’

change

This solution is working fine both in the case of HTTPS and HTTP.

Though this scenario is very specific but still this may help someone to understand the issue better.

Advertisements
  1. March 9, 2017 at 12:01 pm

    Thanks Prasad for the valuable information. I have query just to understand scenario better. Traffic from browser to LB is HTTPS and from LB to IIS(internal n/w) HTTP? How about the other on demand references like js, css links in master pages? whether they been fetched using https or http? any console error related to it?

  2. March 10, 2017 at 4:55 am

    Hi Shankar,

    Thanks for feedback.
    About the CSS and JS reference are connected automatically as I think the references are added by SharePoint as example http://”//ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js”

    This will help to resolve in both the cases.

    BR,
    Prasad Pathak

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: