I am working on one MVC application, where there is separate WEB API project also. Now I want to implement update email functionality based on OTP verification from mobile via WEB API. Web API is stateless but still, I want to implement SESSION in my code so that I can access OTP value in subsequence request and validate it. Currently, I am able to store OTP in session in the first request but in next request Session is null and I can not access stored OTP value.
I do not want database trip to store and retrieve the OTP.
public HttpResponseMessage SendOtpOnMobile([FromBody]OtpOnMobileAPIRequest objOtpOnMobileAPIRequest)
{
otpValue = CommonUtility.GenerateRandomOTP(4);
HttpContext.Current.Session["otpGeneratedValue"] = otpValue;
//Send OTP logic and response code
....
}
public HttpResponseMessage ValidateOtpFromMobile([FromBody]ValidateOtpFromMobileAPIRequest objValidateOtpFromMobileAPIRequest)
{
var otpGeneratedValue = HttpContext.Current.Session["otpGeneratedValue"];
if(objValidateOtpFromMobileAPIRequest.OTP == otpGeneratedValue)
{
//success
}
....
}
I have tried following URLs.