我的ASP.NET Core路由是否可以在localhost上很好地重定向,而在生产环境中却不能重定向?

时间:2019-11-25 13:03:48

标签: asp.net-core asp.net-core-2.2

这是我的启动文件中的配置。

  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变量,请忽略它。我以前使用过但停止了。

0 个答案:

没有答案