c# - 在 POST 调用的情况下用什么代替 LocalRedirect:POST 调用错误
问题描述
在以下处理登录请求的方法中:如果登录成功,我必须在帖子中调用一个页面。post 调用有一个参数,对于调用,我使用标准的 http 方法。
LocalRedirect的语音然后下降。为了使所有工作正常,我应该做什么?
我用 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();
}
POST 调用似乎没有调用该页面。我在被调用页面的控制器中放置了一个断点,但它永远不会在这里停止。对于 post call 我使用这里解释的方法:Response.Redirect with POST 而不是 Get?正如克劳迪奥·卡约·卡斯塔涅蒂(Claudio Cayo Castagnetti)所建议的那样。
提前致谢。
西蒙娜
解决方案
推荐阅读
- sql-server - 如何修复“启动用户态代理时出错:在 Windows 10 上使用 docker 侦听 tcp 0.0.0.0:1433
- sql-server - 如何将此存储过程从 SQL Server 转换为 Postgresql?
- sql-server - Disable_error_and_usage_SQLserver
- javascript - 将图像转换为 Data URI Base64 的问题
- python - 在 pyswip 中获取列表作为 aswer 的问题
- php - Laravel Nova 数字格式
- excel - 没有值时将复制的单元格格式化为空白,即使使用日期、数字或公式也是如此
- javascript - ThreeJS GLTFLoader 材质数组
- android-emulator - Android Automotive Emulator“没有为此目标安装系统映像”
- python - 在 python 游标中读取一列打印很奇怪?