user736893
user736893

Reputation:

Maintaining a "session" with ajax and .net services?

We have a public facing webserver hosted on a local domain. I'm trying to authenticate to a .net web service using domain credentials. I've tried quite a few variants without any success.

The guy that wrote the webservice has now provided init.aspx. If I first do a GET to that URL, I am prompted to login and get a success. However, when I do a subsequent post to http://website.net/cms/api/content/SetContentSectionById I still get 401 (Unauthorized).

Is there a way to pass the "session" or login information back to the server in the POST?

Upvotes: 0

Views: 24

Answers (1)

Mahesh Singh Chouhan
Mahesh Singh Chouhan

Reputation: 2588

You need to generate unique access token or u_id on server side and sent it back to ajax when login credential works.

Then after successful authentication you can use Ajax Header as Authorization to validate the logged in user like this:

$.ajax({
  url: "http://website.net/cms/api/content/SetContentSectionById",
  beforeSend: function(xhr, settings) { 
      xhr.setRequestHeader('Authorization', access_token); 
  },
  success: function(data, status) {
    return console.log("The returned data", data);
  }
});

Upvotes: 1

Related Questions