the 404 I not found. this would imply the either the url or payload is invalid in the _apiService call:
var response = await _apiService.GenerateRegisterOtp(dto);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Register.cshtml
1.
1.
xml @page @model FaceAdminApp.Pages.Auth.RegisterModel @{ ViewData["Title"] = "Register"; } @if (Model.IsPhoneNumberPresent) { <div class="container"> <div class="row justify-content-center"> <div class="col-md-5"> <h5>NEW REGISTER</h5> <div class="card"> <div class="card-body"> <form method="post"> <div class="px-3 my-1 d-flex justify-center"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="CountryCode">Country Code</label> <select class="form-control" id="CountryCode" asp-for="LoginModel.CountryCode"> <option value="+91">+91</option> <option value="+49">+49</option> <option value="+1">+1</option> <option value="+1">+33</option> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="PhoneNumber">Phone Number</label> <input type="text" class="form-control" id="PhoneNumber" asp-for="LoginModel.Username"> </div> </div> </div> </div> <div class="px-3 my-1 d-flex justify-center"> <div> <label for="OTP">OTP</label> <input id="OTP" type="text" class="form-control" asp-for="LoginModel.Password" autocomplete="off" /> </div> <button type="submit" class="btn btn-outline-primary btn-sm ml-4 mt-4" style="width: 150px; " asp-page-handler="GenerateRegisterOtp" disabled="@Model.OtpProcessing"> @if (Model.OtpProcessing) { <div class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"> <span class="visually-hidden">Loading...</span> </div> <span>GENERATING</span> } else { <span>GENERATE OTP</span> } </button> <div class="mt-6 d-flex justify-space-between align-center"> <a asp-page="/Auth/Login" class="btn btn-success btn-sm ml-4 mt-4">LOGIN</a> </div> <button type="submit" class="btn btn-danger btn-sm ml-4 mt-4" style="width: 150px; " asp-page-handler="ValidPhoneNumberSubmit" disabled="@Model.Processing"> @if (Model.Processing) { <div class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"> <span class="visually-hidden">Loading...</span> </div> <span>VALIDATING</span> } else { <span>VALIDATE</span> } </button> </div> </form> </div> </div> </div> </div> </div> } else { <div class="container"> <div class="row justify-content-center"> <div class="col-md-5"> <h5>NEW REGISTER</h5> <div class="card"> <div class="card-body"> <form method="post"> <div class="px-3 my-1 d-flex justify-center"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="CountryCode">Country Code</label> <select class="form-control" id="CountryCode" asp-for="LoginModel.CountryCode"> <option value="+91">+91</option> <option value="+49">+49</option> <option value="+1">+1</option> <option value="+1">+33</option> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="PhoneNumber">Phone Number</label> <input type="text" class="form-control" id="PhoneNumber" asp-for="LoginModel.Username"> </div> </div> </div> </div> <div class="px-3 my-1 d-flex justify-center"> <div> <label for="OTP">OTP</label> <input id="OTP" type="text" class="form-control" asp-for="LoginModel.Password" autocomplete="off" /> </div> <button type="submit" asp-page-handler="GenerateRegisterOtp" class="btn btn-outline-primary btn-sm ml-4 mt-4" style="width: 150px;" disabled="@Model.OtpProcessing"> @if (Model.OtpProcessing) { <div class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"> <span class="visually-hidden">Loading...</span> </div> <span>GENERATING</span> } else { <span>GENERATE OTP</span> } </button> </div> <div class="mt-3 d-flex justify-center align-center"> <!-- Adjust mt-3 for vertical spacing --> <div class="d-flex flex-column align-items-center"> <a asp-page="/Auth/Login" class="btn btn-success mt-4 ml-4" style="width:150px">LOGIN</a> </div> <span style="margin-left: 60px;"></span> <button type="submit" asp-page-handler="ValidPhoneNumberSubmit" class="btn btn-danger btn-sm mt-4 ml-4" style="width: 150px;" disabled="@Model.Processing"> @if (Model.Processing) { <div class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"> <span class="visually-hidden">Loading...</span> </div> <span>VALIDATING</span> } else { <span>VALIDATE</span> } </button> </div> </form> </div> </div> </div> </div> </div> }
Register.cshtml.cs
1.
public async Task<IActionResult> OnPostGenerateRegisterOtpAsync()
{
OtpProcessing = true;
if (string.IsNullOrEmpty(LoginModel.Username))
{
Notify.Add(TempData, false, "", "Phone Number required");
OtpProcessing = false;
return Page();
}
else if (LoginModel.Username.Length < 10)
{
Notify.Add(TempData, false, "", "Enter valid Phone Number");
OtpProcessing = false;
return Page();
}
var dto = new PhoneNumberDto { PhoneNumber = LoginModel.CountryCode + LoginModel.Username };
var response = await _apiService.GenerateRegisterOtp(dto);
if (response.IsSuccess)
{
Notify.Add(TempData, true, $"OTP Generated successfully. ", "");
}
else
{
Notify.Add(TempData, false, "", response.Message);
}
OtpProcessing = false;
return Page();
}
public async Task<ResponseDto<string>> GenerateRegisterOtp(PhoneNumberDto dto)
{
var httpResponse = await _httpService.Post<PhoneNumberDto, ResponseDto<string>>(
"/api/identity/generateregisterotp", dto);
if (!httpResponse.Success)
throw new ApplicationException(await httpResponse.GetBody());
return httpResponse.Response;
}
Controller.cs
1.
1.
typescript [AllowAnonymous] [HttpPost("generateregisterotp")] public async Task<ResponseDto<string>> GenerateRegisterOTP(PhoneNumberDto phoneNumber) { try { var existingUser = await _context.GetAppUserByUsername(phoneNumber.PhoneNumber); if (existingUser != null) { return new ResponseDto<string>(false, $"The {phoneNumber.PhoneNumber} is already registered"); } var otp = new Random().Next(111947, 999999).ToString(); var result = await _context.RegisterSetOtpAsync(phoneNumber.PhoneNumber, otp); if (result) { return new ResponseDto<string>(true, $"OTP sent successfully", ""); } } catch (Exception ex) { return new ResponseDto<string>(false, ex.Message); } return new ResponseDto<string>(false, "Server is not responding"); }
While generating OTP for new User facing this issue from the server(404 error)
at these lines
VacApiService.cs
+
Register.cshtml.cs
+
the 404 I not found. this would imply the either the url or payload is invalid in the _apiService call:
var response = await _apiService.GenerateRegisterOtp(dto);