Cookies Blazor服务器&x2B;Azure B2C标识-更改Cookie名称
在为B2C创建具有身份验证的stock Blazor服务器应用程序(文件/新)时,您会得到一个如下所示的Cookies Blazor服务器&x2B;Azure B2C标识-更改Cookie名称,cookies,azure-active-directory,azure-ad-b2c,blazor,Cookies,Azure Active Directory,Azure Ad B2c,Blazor,在为B2C创建具有身份验证的stock Blazor服务器应用程序(文件/新)时,您会得到一个如下所示的Startup.cs B2C本身是有效的,但我只是尝试更改Cookie名称。默认情况下,它显示为(.AspNetCore.AzureADB2CCookie) 我怎样才能改变它 我尝试了以下似乎不起作用的方法: (一) (二) Startup.cs public void ConfigureServices(IServiceCollection services) {
Startup.cs
B2C本身是有效的,但我只是尝试更改Cookie名称。默认情况下,它显示为(.AspNetCore.AzureADB2CCookie
)
我怎样才能改变它
我尝试了以下似乎不起作用的方法:
(一)
(二)
Startup.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");
});
}
public void配置服务(IServiceCollection服务)
{
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options=>Configuration.Bind(“AzureAdB2C”,options));
services.AddRazorPages();
AddServerSideBlazor();
services.AddSingleton();
AddHttpContextAccessor();
}
//此方法由运行时调用。使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(“/Error”);
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage(“/_主机”);
});
}
服务。配置(
AzureADB2CDefaults.CookieScheme,选项=>
{
options.Cookie.Name=UIConstants.WebSessionCookieName;
});
B2c设置会话cookie,我尝试设置ExpireTimeSpan使其持久化。但它似乎不起作用。
.AddCookie(x =>
{
x.Cookie.Name = UIConstants.WebSessionCookieName;
});
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;
});