Monday, March 25, 2019

Refused to get "Unsafe Header - Location" while getting response header in item service

Hi,
     
        Today i'm going to share my issue experience while creating item using item service in sitecore.services.client.


REST API is one of the key features in sitecore.

Sitecore provides two ways to use REST API
.
1. Item Service
2. Entitiy Service

If you want more explanation please refer the below url
https://doc.sitecore.com/developers/90/sitecore-experience-management/en/the-restful-api-for-the-itemservice.html

Issue: 
         
I'm trying to create an item using ItemService in Sitecore.Services.Client.
Item creation is working fine and response looks like this:
201 (Created).
Location: /item/0727f965-2338-43cc-bd88-5071ad3f7a12?database=master
My need is to get this location in the response header.
During that I'm facing this issue:
refused to get unsafe header "Location" Error
my code sample:
 request.setRequestHeader('Access-Control-Expose-Headers', 'Location');
            request.onreadystatechange = function () {
                if (this.readyState == 4) {
                    console.log(this.status); 
                    console.log(this.getResponseHeader('Location'));                                       
                }
            };
Solution:
I found the solution by adding the below line in web.config.
<httpProtocol>
      <customHeaders>
        <add name="Access-Control-Expose-Headers" value="*"/>
        <remove name="X-Powered-By" />
      </customHeaders>
 </httpProtocol>

2 comments:

  1. So this is a pretty awesome update (not sure exactly when this update occurred) - but you can now instantly print all QR codes to videos in a particular topic! dramacool-eng.com

    ReplyDelete
  2. Simply enter into your topic and look above the first video (to the right). You will see the embedded picture below. kissasianbox.net

    ReplyDelete

Check the users Logged into the sitecore backend

Hi, Today I'm going to discuss about " how to check the concurrent users logged into the sitecore backend ? ". For this ...