what I want to do is using HttpContext.Session in the API
in the same WebApi Controller but different actions.
$.ajax({
url:baseAppUrl+"api/login",
type:"post",
data:{
action:"sms",
username:"",///mobile phone
},
success:function(ret,err){
}
it will give me a code and then use the code to login.
but after the ajax send the reqeust again I can not get the HttpContext.Session.
I am using .net core 3.1
if (action.Equals("sms"))
{
if (string.IsNullOrEmpty(username))
{
return Json(new { Ok = false, Message = "parameter is null" });
}
Random rnd = new Random();
var verifyCode = rnd.Next(111111, 999999).ToString();
HttpContext.Session.SetString("code", verifyCode);
return Json(new { Ok = true, Message = verifyCode });
}
and in the login action:
if (action.Equals("mobileLogin"))
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(code))
{
return Json(new { Ok = false, Message = "paremeter is null" });
}
var userCode = HttpContext.Session.GetString("code"); //the userCode will be null.
if (!string.IsNullOrEmpty(userCode))
{
////.....
}
}
but with the postman all is worked.
why?
