Professional Documents
Culture Documents
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Mvc;
if (isOtpSent)
{
// OTP sent successfully
// You can store the OTP in the session or database for verification
later
TempData["otp"] = otp;
return View();
}
else
{
// Error handling if OTP sending fails
return View("Error");
}
}
[HttpPost]
public ActionResult VerifyOtp(string enteredOtp)
{
// Retrieve the previously generated OTP from TempData
string storedOtp = TempData["otp"] as string;
if (enteredOtp == storedOtp)
{
// OTP verification successful
ViewBag.Message = "OTP verified successfully!";
}
else
{
// Incorrect OTP
ViewBag.Message = "Incorrect OTP. Please try again.";
}
return View("Index");
}
try
{
HttpResponseMessage response = await client.GetAsync(apiUrl);
response.EnsureSuccessStatusCode();
return true;
}
catch (HttpRequestException)
{
// Handle exceptions here
return false;
}
}
}