【发布时间】:2020-03-05 10:42:33
【问题描述】:
我已经构建了一个 ASP.NET CORE MVC 应用程序并使用 cookie 身份验证。下面是我在 Startup.cs 文件中的代码。
services.AddAuthentication(options =>
{
// these must be set other ASP.NET Core will throw exception that no
// default authentication scheme or default challenge scheme is set.
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/Account/Login/";
});
当 cookie 过期时,应用程序会重定向到 /Account/Login 路径,返回 URL 包含用户所在的当前 url。这可以正常工作,直到当前 url 具有 0 或 1 查询参数。如果当前 url 有 2 个查询参数,那么只有第一个查询参数被传递给返回 URL。登录方式如下。
public IActionResult Login(string returnUrl)
{
return View(new LogInViewModel { ReturnUrl = returnUrl });
}
例如
如果当前 URL 是 /Inspection?inspectionID=1&processTypeID=2,则返回 url 仅获得 /Inspection?inspectionID=1。 processtypeID 参数不来。
但是当cookie过期时浏览器导航到/Account/Login的URL时,会显示正确的url/Account/Login?ReturnUrl=/Inspection?inspectionID=1&processTypeID=2
谁能指出为什么会发生这种情况以及如何解决这个问题?
谢谢, 泽涵
【问题讨论】:
-
如果“ReturnUrl”是查询字符串,那么“processTypeID”是什么样的?
标签: asp.net-core-mvc cookie-authentication