Microsoft.AspNetCore.SignalR.Client的.Net客户端传送Token的最佳方法!
如下将Authorization标头添加到HubConnectionBuilder中,如下所示:
对于不记名令牌->
HubConnection = new HubConnectionBuilder() .WithUrl($"https://10.0.2.2:5001/chatHub", (opts) => { opts.Headers.Add("Authorization", new AuthenticationHeaderValue( "Bearer","YOUR_TOKEN").ToString()); }) .Build();
您也可以像这样使用基本令牌->
HubConnection = new HubConnectionBuilder() .WithUrl($"https://10.0.2.2:5001/chatHub", (opts) => { opts.Headers.Add("Authorization", new AuthenticationHeaderValue( "Basic", Convert.ToBase64String( Encoding.Default.GetBytes( "Username" +":" +"Password" ))).ToString()); }) .Build();
不能直接操作HubConnection.Headers, 老版本中有这些方法,后续都统一到options集合中了。
标签:AspNetCore,HubConnectionBuilder,HubConnection,SignalR,Token,Authorization,new,op From: https://www.cnblogs.com/pccai/p/18108241