Question

Sitecore ItemWebApi Gurus,

Why am I getting a response of "Access to site is not granted" every time I attempt to make a Sitecore ItemWebApi request?

Here are the security settings in my Sitecore.ItemWebApi.config

<site name="website">
    <patch:attribute name="itemwebapi.mode">StandardSecurity</patch:attribute>
    <patch:attribute name="itemwebapi.access">ReadOnly</patch:attribute>
    <patch:attribute name="itemwebapi.allowanonymousaccess">false</patch:attribute>
  </site>
</sites>

Here's how I'm setting up my ItemWebApi request (please note that I have used a fake username, password, and GUID for the purpose of stack overflow):

  var client = new WebClient();

  var n = new NameValueCollection();
  n["X-Scitemwebapi-Username"] = "extranet\\Sample_Username";
  n["X-Scitemwebapi-Password"] = "SamplePassword";

  client.Headers.Add(n);

  var result = client.DownloadString(
            "http://localhost:11111/-/item/v1/?sc_itemid={11111111-1111-1111-1111-111111111111}&scope=c");

The response I get back from my request is always:

Access to site is not granted

I'm using sitecore 7.1.

Was it helpful?

Solution

Turns out I was using the wrong password for the user. The code above in my question is perfectly valid and will return a json response containing the desired information about a sitecore item.

I'd like to also add that you need to verify that the sitecore user which you are trying to authenticate with has been "enabled" in sitecore. I had added a user for my Item Web Api through a sitecore package and wasn't aware that when you do that, sitecore by default disables the user. You actually have to manually "enable" the user before it is active.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top