Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am facing an issue while using CSOM in SharePoint 2013. I have configured an alternate access mapping for our site to run on http://mycustomdoamin.net/ 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 as “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

1 Answer 1

I have the same problem but in my case I'm using Office365 and with and with a site colecction 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:

_spBodyOnLoadFunctionNames.push("InitializeObjects_fromPagecontextInfo");

function InitializeObjects_fromPagecontextInfo() {
RelativeSiteUrl = _spPageContextInfo.siteServerRelativeUrl;}

Sincerely, Mario Cortés

share|improve this answer

Your Answer

 
discard

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.