使用 asp.net 时如何更改登录名 url 5
How to change login url when using asp.net 5
我正在使用 asp.net 5 和 Identity 3 对用户进行身份验证,但它总是重定向到默认登录名 url,即 "Account/Login"。我想更改它,但似乎没有任何地方可以设置此选项。我在 Configure() 方法中使用 AddIdentity() 。请帮忙。
谢谢
app.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/Admin/Login");
options.LogoutPath = new PathString("/Admin/LogOff");
},
IdentityOptions.ApplicationCookieAuthenticationScheme
);
使用 .Net Core 1.0.0 + Identity + Facebook OAuth,已接受的答案不再编译。这是有效的:
public void ConfigureServices(IServiceCollection services)
{
(...)
services.Configure<IdentityOptions>(options =>
{
options.Cookies.ApplicationCookie.LoginPath = new PathString("/Login");
options.Cookies.ApplicationCookie.LogoutPath = new PathString("/Logoff");
});
}
使用 ASP.NET Core 1.1 + Identity 我用这个 :
public void ConfigureServices(IServiceCollection services)
{
(...)
services.AddIdentity<ApplicationUser, IdentityRole>(x =>
{
x.Cookies.ApplicationCookie.LoginPath = new PathString("/Admin/Login");
x.Cookies.ApplicationCookie.LogoutPath = new PathString("/Admin/LogOff");
}
}
使用 ASP.NET Core 2.0 + Identity,这已更改为:
services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/LogIn");
更多关于 migrating to 2.0 here。
我正在使用 asp.net 5 和 Identity 3 对用户进行身份验证,但它总是重定向到默认登录名 url,即 "Account/Login"。我想更改它,但似乎没有任何地方可以设置此选项。我在 Configure() 方法中使用 AddIdentity() 。请帮忙。 谢谢
app.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/Admin/Login");
options.LogoutPath = new PathString("/Admin/LogOff");
},
IdentityOptions.ApplicationCookieAuthenticationScheme
);
使用 .Net Core 1.0.0 + Identity + Facebook OAuth,已接受的答案不再编译。这是有效的:
public void ConfigureServices(IServiceCollection services)
{
(...)
services.Configure<IdentityOptions>(options =>
{
options.Cookies.ApplicationCookie.LoginPath = new PathString("/Login");
options.Cookies.ApplicationCookie.LogoutPath = new PathString("/Logoff");
});
}
使用 ASP.NET Core 1.1 + Identity 我用这个 :
public void ConfigureServices(IServiceCollection services)
{
(...)
services.AddIdentity<ApplicationUser, IdentityRole>(x =>
{
x.Cookies.ApplicationCookie.LoginPath = new PathString("/Admin/Login");
x.Cookies.ApplicationCookie.LogoutPath = new PathString("/Admin/LogOff");
}
}
使用 ASP.NET Core 2.0 + Identity,这已更改为:
services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/LogIn");
更多关于 migrating to 2.0 here。