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.