我使用的是ASP.NET Core2.1,我使用了脚手架来添加身份,它工作得很好,除了当我试图转到一个需要登录的页面时,它会把我带到:/Identity/Account/Login?ReturnUrl
如何将其更改为仅转到/Account/Login,这是我自己创建的登录页面。
我试过这个:
services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = "/Account/AccessDenied";
options.Cookie.Name = "Cookie";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(720);
options.LoginPath = "/Account/Login";
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
options.SlidingExpiration = true;
});
但它仍然转到/Identity/
发布于 2018-09-11 06:01:42
我刚刚遇到了同样的问题。我把我的
在ConfigureServices
中的services.AddIdentity
调用之后调用services.ConfigureApplicationCookie
发布于 2018-06-01 09:19:02
尝试添加new PathString("...")
并在控制器中设置路由。
services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = new PathString("/Account/AccessDenied");
options.Cookie.Name = "Cookie";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(720);
options.LoginPath = new PathString("/Account/Login");
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
options.SlidingExpiration = true;
});
[AllowAnonymous]
[Route("Account")]
public class SecurityController : Controller
{
[Route("Login/{returnUrl?}")]
public IActionResult Login(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}
}
发布于 2018-08-23 21:29:46
如果您有以下条件,请检查您是如何注册身份服务的:
services.AddDefaultIdentity<IdentityUser>(options => { }) .AddEntityFrameworkStores<ApplicationDbContext>();
将其替换为
services.AddIdentity<IdentityUser, IdentityRole>(options => { }) .AddEntityFrameworkStores<ApplicationDbContext>();
,并将您的代码保存在在我的例子中有效的ConfigureApplicationCookie
中。
https://stackoverflow.com/questions/50633896
复制相似问题