在ASP.NET Core 3.1中,OpenIDConnect中的message.state为null的问题可能是由于未正确配置Authentication中间件或未正确处理回调中的状态参数引起的。以下是一个可能的解决方案:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
// 其他配置项...
});
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
app.Use(async (context, next) =>
{
if (context.Request.Path.StartsWithSegments("/signin-oidc") && context.Request.Query["state"].Count == 0)
{
context.Request.QueryString = context.Request.QueryString.Add("state", "default_state");
}
await next.Invoke();
});
希望这些解决方案能帮助您解决ASP.NET Core 3.1 OpenIDConnect中message.state为null的问题。
上一篇:Asp.Net Core 3.1 OData不支持使用属性路由和带参数的函数。
下一篇:ASP.NET Core 3.1 Razor Pages Web应用:即使使用Ajax调用,为什么Razor页面表单数据仍然被清除的原因是什么?