C# 多个Blazor服务器应用程序和Azure身份验证注销问题
我有2个Blazor服务器端应用,每个应用都在Azure AD中注册了自己的应用程序。它们在VS2019、.NET Core 3.0中创建一个新的Blazor服务器端应用程序几乎是现成的 当它们在浏览器的两个选项卡中打开并且我从应用程序a注销时,我仍然能够浏览应用程序B中的页面链接。在我按下浏览器的页面刷新按钮之前,应用程序B看不到我已注销 我尝试将@attribute[Authorize]添加到页面中,在App.razor页面中定义C# 多个Blazor服务器应用程序和Azure身份验证注销问题,c#,blazor,asp.net-core-3.0,blazor-server-side,C#,Blazor,Asp.net Core 3.0,Blazor Server Side,我有2个Blazor服务器端应用,每个应用都在Azure AD中注册了自己的应用程序。它们在VS2019、.NET Core 3.0中创建一个新的Blazor服务器端应用程序几乎是现成的 当它们在浏览器的两个选项卡中打开并且我从应用程序a注销时,我仍然能够浏览应用程序B中的页面链接。在我按下浏览器的页面刷新按钮之前,应用程序B看不到我已注销 我尝试将@attribute[Authorize]添加到页面中,在App.razor页面中定义,并在OnInitializedAsync页面中使用Authe
,并在OnInitializedAsync
页面中使用AuthenticationStateProvider
功能检查.isauthorized
是否成功
@page "/fetchdata"
@attribute [Authorize]
[CascadingParameter] Task<AuthenticationState> authenticationStateTask { get; set; }
protected override async Task OnInitializedAsync()
{
var authState = await authenticationStateTask;
var user = authState.User;
if (!user.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("Error");
}
}
@page”/fetchdata
@属性[授权]
[CascadingParameter]任务authenticationStateTask{get;set;}
受保护的重写异步任务OnInitializedAsync()
{
var authState=等待authenticationStateTask;
var user=authState.user;
如果(!user.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo(“错误”);
}
}
请登录。
对不起,这个地址什么也没有
public void配置服务(IServiceCollection服务)
{
AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(选项=>Configuration.Bind(“AzureAd”,选项));
services.addcontrollerswithview(选项=>
{
var policy=new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
options.Filters.Add(新的授权过滤器(策略));
});
services.AddRazorPages();
AddServerSideBlazor();
services.AddSingleton();
services.AddServerSideBlazor().AddCircuitOptions(选项=>{options.DetailedErrors=true;});
services.AddSingleton();
}
这可能与Chrome和Firefox等Web浏览器对SameSite for Cookie的实现进行突破性更改有关
您可以尝试以下描述的缓解步骤:
这可能与Chrome和Firefox等Web浏览器对SameSite for Cookie的实现进行突破性更改有关 您可以尝试以下描述的缓解步骤:
1)这种情况是否发生在Google Chrome以外的Web浏览器上(最新的浏览器由于同一个站点的cookie问题而出现注销问题)2)这种情况是发生在生产环境中还是仅发生在本地主机上?很抱歉回复太晚-这已部署到我们内部网上的Web服务器上。我将使用Chrome以外的其他浏览器进行检查。谢谢你的建议!事实上,它在Edge和IE中的工作与预期一样。我将不得不研究是否有针对Chrome的修复程序。非常感谢您的帮助。1)这种情况是否发生在Google Chrome以外的Web浏览器上(最新的一款浏览器由于同一个站点的cookie问题而出现注销问题)2)这种情况是发生在生产中还是仅发生在本地主机上?很抱歉,回复太晚-这已部署到我们内部网上的Web服务器上。我将使用Chrome以外的其他浏览器进行检查。谢谢你的建议!事实上,它在Edge和IE中的工作与预期一样。我将不得不研究是否有针对Chrome的修复程序。非常感谢你的帮助。谢谢-我想这是正确的。在3.0的补丁发布之前,我会一直关注补丁。谢谢-我认为这是正确的。在3.0的补丁发布之前,我会一直关注补丁。
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<h1>Please Log In.</h1>
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
services.AddSingleton<TestContextService>();
}