这是我的启动文件中的配置。
app.UseMvc(routes =>
{
routes.MapRoute(
name: "adminlogin",
template: "{controller=AdminLogin}/{action=Index}");
routes.MapRoute(
name: "allreceivedproposals",
template: "{controller=AdminLogin}/{action=AllReceivedProposals}/{proposalname?}");
routes.MapRoute(
name: "allpendingproposals",
template: "{controller=AdminLogin}/{action=AllPendingProposals}/{proposalname?}");
routes.MapRoute(
name: "default",
template: "{controller=OperatorCompany}/{action=Index}/{id?}");
});
在localhost上,登录后我可以访问https://localhost:44325/operatorcompany/index。但是, https://drillingtest.azurewebsites.net/operatorcompany/index在登录后始终返回404。
这也是我在控制器中的登录操作。
[HttpGet]
[AllowAnonymous]
public IActionResult Login(string returnUrl = null)
{
// Clear the existing external cookie to ensure a clean login process
ViewData["ReturnUrl"] = returnUrl;
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
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.Email, model.Password,
model.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
var user = await _userManager.FindByEmailAsync(model.Email);
_logger.LogInformation("User logged in.");
return RedirectToAction("Index","OperatorCompany");
}
if (result.RequiresTwoFactor)
{
return RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToAction(nameof(Lockout));
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return View(model);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
您会注意到returnUrl变量,请忽略它。我以前使用过但停止了。