Digambar Malla
Digambar Malla

Reputation: 335

Getting header value during Ajax Call

While I am doing ajax call, I want access header value present in WEBAPI,How to call the header value.

Header is of this fromat in WEBAPI:

HttpContext.Current.Response.AppendHeader("SECURITY_TOKEN_KEY", TokenManager.CreateToken(objUserAuthentication.SUA_Login_Id));

Upvotes: 2

Views: 924

Answers (2)

Prashant-Systematix
Prashant-Systematix

Reputation: 269

Hi simply you can use getAllResponseHeaders method to get all header value.Then you can filter out the required one based on key name.

var geturl;
  geturl = $.ajax({
    type: "GET",
    url: 'http://....',
    success: function () {
      alert("done!"+ geturl.getAllResponseHeaders());
    }
  });

Upvotes: 0

Zaheer Ul Hassan
Zaheer Ul Hassan

Reputation: 759

You can pull it from the request headers as follows:

var headers = Request.Headers.GetValues("AjaxHeader");
var ajaxHeader = headers.FirstOrDefault();

Hope it helps.

Get header from web method

How to retrieve Ajax header in this asp.NET web api method?

Upvotes: 1

Related Questions