












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集合中了。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。