Asp.net-Identity
AspNetCore - 使用 Google 身份驗證時更改 cookie 名稱
在 ASP.NET 5、MVC 6 中,我能夠在選項中更改外部身份驗證 cookie 的名稱——但這似乎已從
AspNetCore.IdentityRC2庫中的新提供程序中刪除。我有這個設置;
class Startup { ... public void ConfigureServices(IServiceCollection services){ services.AddIdentity<Member, Role> ... // identity wired up } public void Configure(IApplicationBuilder app, ILoggerFactory logger) { // .. other wiring app .UseIdentity() .UseGoogleAuthentication (new GoogleOptions { ClientId = Constants.Google.Client, ClientSecret = Constants.Google.Secret, Scope = {"email", "profile"} }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } }曾經有一個
AuthenticationType屬性可以設置為 astring,它可以控制 cookie 名稱;但那已經過去了。我讀了其他文章說要嘗試
SignInScheme並且AuthenticationScheme- 我做到了,但這會開始給我一個錯誤,即存在No Provider to Handle this Scheme.有什麼我可以做的嗎?
下面介紹如何替換用於外部 cookie 的預設名稱。
services.AddIdentity<Member, Role>(options => { options.Cookies.ExternalCookie.CookieName = "name"; });
它在 VS2017 中對我有用
在 Startup.cs ConfigureServices() 中:
services.ConfigureApplicationCookie(options => { options.Cookie.Name = "NewCookieName"; });