SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am facing an issue while using CSOM in SharePoint 2013. I have configured an alternate access mapping for our site to run on The site is running fine and I am able to see the pages.

Now I am trying to use CSOM to get the current SP context and execute a query. At that point, I am getting error:

Unexpected data from server

On investigating with Fiddler, I found that SharePoint is making a call to http://mycustomdoamin/_api/contextinfo.

Note that the above is NOT the FQDN that I have configured my site for. It is missing the .net domain extension. Consequently, I am getting a 502 DNS lookup failed error.

The same script works fine when running without the mapping (e.g. on http://ServerName ). I have also tried setting up hosts file entry for the domain but that too doesn’t work.

What am I doing wrong here?

share|improve this question

I have the same problem but in my case I'm using Office365 and with and with a site collection that isn't is the root of sitecollection (/sites/mysite).

I'm not sure about the problem but when I whatch the variable with the SP.ClientContext.get_current() value I have showed that the "$u_0" property has the value "https://mysubscription.sharepoint" so when CSOM try to make the calls it has the same error.

I have founded two solutions that dependeds of your solutions:

The first option, set the "$u_0" property before you call the executeQueryAsync method. For example:

function FixContext(Context) {
if (Context.$u_0.indexOf(".sharepoint") > 0)
    if (Context.$u_0.indexOf(".com") < 0)
        Context.$u_0 += ".com";

return Context;}

The second option consist on use the "_spPageContextInfo" variable:


function InitializeObjects_fromPagecontextInfo() {
RelativeSiteUrl = _spPageContextInfo.siteServerRelativeUrl;}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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