ASP.NETCore5:OpenIDConnect破坏了默认/根路由
创始人
2024-09-17 12:30:25
0

在ASP.NET Core 5中,OpenIDConnect的配置可能会出现问题,使得默认/根路由无法正常工作。这是因为OpenIDConnect在添加Authentication Middleware时,会更改默认的路由:

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller}/{action}/{id?}");
    
    endpoints.MapRazorPages();
});

这里的问题在于,OpenIDConnect内部定义了一个“UseAuthentication” Extension方法,该方法将默认的authenticationScheme更改为OpenIDConnect的方案名称(“OpenIdConnectDefaults.AuthenticationScheme”),而RazorPages或ControllerRoute的Endpoint将使用此authenticationScheme。(通常在配置Auth的时候我们会在Add[认证]中添加authenticationScheme,但是如果不指定Scheme,他会默认使用系统的authenticationScheme) 如果您的应用依赖于默认路由,则需要在配置OpenIDConnect之前将Authentication Middleware添加到管道中:

app.UseRouting();
app.UseAuthentication(); //add this line before OpenIDConnect
app.UseAuthorization();

app.UseOpenIdConnectAuthentication(...);// your open id config here

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller}/{action}/{id?}");
    
    endpoints.MapRazorPages();
});

通过在OpenIDConnect之前添加Auth中间件,您可以确保应用程序的默认/根路由仍然会正常工作。

相关内容

热门资讯

重大消息!aapoker插件,... 重大消息!aapoker插件,hhpoker软件可以玩吗,其实是有挂(有挂总结)能透视中分为三种模型...
必备攻略!wepokerplu... 必备攻略!wepokerplus辅助,wepoker买钻石有用吗,确实存在有挂(详细教程);破解侠是...
重大消息!德普之星透视免费,w... 重大消息!德普之星透视免费,wepoker网页版透视方法,竟然是有挂(有挂存在)1、该软件可以轻松地...
总算明白!hhpoker辅助软... 总算明白!hhpoker辅助软件是真的么,wpk官网下载链接,本来存在有挂(有挂详情)1、很好的工具...
一分钟了解!德州局透视脚本下载... 一分钟了解!德州局透视脚本下载安装最新版本,智星德州插件2024最新版,都是有挂(有挂工具)小薇(辅...
必看攻略!hhpoker有没有... 必看攻略!hhpoker有没有作弊辅助,wepoker有没有插件,真是真的是有挂(有挂分享)1、该软...
必备攻略!wepoker究竟有... 必备攻略!wepoker究竟有没有透视,aapoker辅助插件工具,好像存在有挂(有挂秘籍)1、有没...
分享一款!xpoker辅助助手... 分享一款!xpoker辅助助手,wepoker怎么看底牌,其实真的有挂(有挂助手)1. 选牌创建新账...
交流学习经验!购买的wpk辅助... 交流学习经验!购买的wpk辅助在哪里下载,德普之星怎么开辅助,竟然真的是有挂(有挂总结)1、脚本辅助...
让我来分享经验!wepoker... 让我来分享经验!wepoker私人定制透视,拱趴游戏破解器,确实有挂(存在有挂)透视方法中分为三种模...