You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Web PubSub与服务端认证:ASP.NET端点验证位置咨询

如何在ASP.NET应用中验证Azure Web PubSub的简易认证码?

我有一个作为事件处理服务的简易ASP.NET应用,现有代码如下:

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services
    .AddWebPubSub(options => options.ServiceEndpoint = new ServiceEndpoint(WebPubSubConnectionString))
    .AddWebPubSubServiceClient<WebPubSubHub>();

WebApplication app = builder.Build();

app.MapWebPubSubHub<WebPubSubHub>("/eventhandler");
app.Run();

我已在Azure Web PubSub中配置了Webhook URL,并采用Azure建议的简易认证码方案保护公开的/eventhandler端点,配置的URL模板为:

https://a9e5-92-253-212-316.ngrok-free.app/eventhandler?code=RRRRR

我尝试直接将带认证码的URL映射到Hub:

app.MapWebPubSubHub<WebPubSubHub>("/eventhandler?code=RRRRR")

但触发了如下异常:

Microsoft.AspNetCore.Routing.Patterns.RoutePatternException: 'The literal section 'eventhandler?code=RRRRR' is invalid. Literal sections cannot contain the '?' character.'

请问在ASP.NET应用中应该在哪里验证这个认证码?

内容的提问来源于stack exchange,提问作者Darkside

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 05:57:38