Blazor服务器+Azure B2C身份-更改Cookie名称



当创建一个带有B2C身份验证的股票Blazor Server应用程序(文件/新建(时,您会得到一个Startup.cs,如下所示。

B2C本身是可行的,但我试图简单地更改Cookie名称。默认情况下,它显示为(.AspNetCore.AzureADB2CCookie(

我该怎么改?

我尝试了以下似乎不起作用:

1(

services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = UIConstants.WebSessionCookieName;
});

2(

.AddCookie(x =>
{
x.Cookie.Name = UIConstants.WebSessionCookieName;
});

启动.cs

public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddHttpContextAccessor();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
services.Configure<CookieAuthenticationOptions>(
AzureADB2CDefaults.CookieScheme, options =>
{
options.Cookie.Name = UIConstants.WebSessionCookieName;
});

相关内容

  • 没有找到相关文章

最新更新