通常(例如在我的本地主机上),[Authorize]
正确重定向LoginPath
到CookieAuthenticationOptions
.
但是,当我部署到我的登台站点 ( staging.mysite.com
) 时,授权重定向似乎放错了部分 url。就我而言,它将:
http://staging/Account.mysite.com/Login?ReturnUrl=%2FHome%2FAuthorize
什么时候应该去:
http://staging.mysite.com/Account/Login?ReturnUrl=%2FHome%2FAuthorize
该应用程序非常基本:
//Startup.cs
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = "/Home/Unauthorized";
options.ReturnUrlParameter = "ReturnUrl";
});
services.AddMvc()
//....
app.UseMvc();
我的控制器:
//HomeController.cs
[Route("[controller]/[action]")]
public class HomeController : Controller
{
[Authorize]
public IActionResult Authorize()
{
return Ok("You are authorized");
}
}
//AccountController.cs
[Route("[controller]/[action]")]
public class AccountController : Controller
{
public IActionResult Login()
{
return View(new LoginViewModel());
}
}
任何人都看到我要去哪里错了吗?
更新:
奇怪的是,如果我进行下面的更改,它会起作用。因此,问题似乎在于在路线中指定了操作?
options.LoginPath = "/Login"; //I removed /Account
[HttpGet("/Login")] //I added the "/Login" template
public IActionResult Login()