In the following method that processes the login request: in case of login ok I have to call a page in post. The post call has one parameter and for the call I use standard http method.
The speech of the LocalRedirect then declines. What should I put in order to make all working?
I indicated the point in the code with the TO DO.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model)
{
if (!string.IsNullOrEmpty(ErrorMessage))
{
ModelState.AddModelError(string.Empty, ErrorMessage);
}
// Se non viene passato un url specifico lo setto sul default
model.ReturnUrl = model.ReturnUrl ?? Url.Content("/Telemetries/Pagina2");
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, lockoutOnFailure: true);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
//activity log
ApplicationUser CurrentUser = await GetCurrentUserAsyncbyUsername(model.Username);
_activityLogService.InsertActivity(CurrentUser,
"LoginUser",
"User Logged ({0})",
model.Username,
CurrentUser.Id);
List<DeviceSetup> devices = _deviceService.GetList(CurrentUser.CustomerId);
if (devices!=null && devices.Count!=0)
{
Devices device = _deviceService.GetDeviceByDeviceId(devices[0].DeviceId);
// TO DO
await WebExtensions.RedirectWithData(device.SerialNo, model.ReturnUrl, HttpContext);
}
else
{
model.ReturnUrl = Url.Content("~/");
return LocalRedirect(model.ReturnUrl);
}
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout");
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return View(model);
}
}
// If we got this far, something failed, redisplay form
return View();
}
The POST call seems not call the page. I put a breakpoint in the controller of the called page but it never stops here. For the post call I use the method explained here : Response.Redirect with POST instead of Get? as suggested me by Claudio Cayo Castagnetti.
Thanks in advance.
Simone