Sourabh Dhiman

Sourabh Dhiman

  • 1.8k
  • 323
  • 34.1k

web api and jquery .

Jul 31 2019 3:30 AM
How to store session value into database use web api Controller and jquery.
 
This is my  code. Any idea  
 
[HttpPost]
public string Login(SessionModel model)
{
var session = HttpContext.Current.Session;
if (session != null)
{
if (session["username"] == null)
session["username"] = "post:" + DateTime.Now.ToString();
return "pass session: " + model.UserName + " --- " + session["username"].ToString();
}
else
{
return "session error!";
}
---
 
function PassModel() {
debugger;
var SessionModel = {
UserName: $('#username').val(),
User_Pwd: $('#Password').val()
}
$.ajax({
type: "Post",
url: 'http://localhost:4490/api/Login',
data: JSON.stringify(SessionModel),
contentType: 'application/json',
success: function (result) {
alert("session");
}
});
}
 
This is jquery code. 
 

Answers (2)