We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Setting the Authorize header to use a bearer token

Hi,

Can you please showcase how can I intercept the request being sent to the server to add an authorization token to the request?


Kind Regards,
Pedro Salgueiro

3 Replies

ES Ezhil S Syncfusion Team December 1, 2015 03:12 PM UTC

Hi Pedro,

Thank you for contacting Syncfusion support.

To add an Authorization header on file upload request, we suggest you to use setRequestHeader in ClientSideOnBegin event. Using setRequestHeader you can add a header to Http request in xhr element. But for browsers below IE10 xhr will not be available in that case we suggest you to use ActiveXObject. Once the header is set you can access it in the handler from the HttpRequest.Headers. Please refer the following code example,
<code>
[ASPX]
<ej:UploadBox ID="upload1" runat="server" SaveUrl="saveFiles.ashx" RemoveUrl="removeFiles.ashx" ClientSideOnBegin="OnBegin"></ej:UploadBox>
[Script]

        function OnBegin(args) {

            if (!this._isXhrSupported()) // to check xhr supported browsers

                xhr = new ActiveXObject("Microsoft.XMLHTTP");

            else

                xhr = new XMLHttpRequest(); // IE10 and below

            xhr.open("post", "saveFiles.ashx", true);

            xhr.setRequestHeader("Authorization", "Uploadbox");

            xhr.send(null);
        }
</code>

Sample prepared can be downloaded from below link:
http://www.syncfusion.com/downloads/support/forum/121305/ze/Upload_f121231-816692230

Please let us know if you have any other queries.

Regards,
Ezhil S



PS Pedro Salgueiro December 1, 2015 03:25 PM UTC

Hi Ezhil,

I'm sorry but either I placed this thread under the wrong category (asp.net) or it was moved by mistake. 

I am using the Javascript control and not the ASP.NET control. Is the begin event equivalent? Should we set the Cancel flag to true to prevent the control from making the request?

Because this issue was quite urgent for us I have also opened the incident 147914 related with the same topic.

Kind Regards,
Pedro


GA Gurunathan A Syncfusion Team December 8, 2015 05:27 PM UTC

Hi Pedro,

We apologies for the late reply.  

We have updated our response for your query in the incident which  was created from your account. So kindly follow up the incident for further queries.

Please let me know if any concerns.

Regards,
Gurunathan

Loader.
Up arrow icon