前端:
引用signalr三方包
This commit is contained in:
@@ -42,7 +42,7 @@ namespace IM_API.Hubs
|
||||
}
|
||||
var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
await _messageService.SendPrivateMessageAsync(int.Parse(userIdStr),dto.ReceiverId,dto);
|
||||
await Clients.Users(dto.ReceiverId.ToString()).SendAsync("ReceiveMessage", userIdStr, dto.Content);
|
||||
await Clients.Users(dto.ReceiverId.ToString()).SendAsync("ReceiveMessage", dto);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,13 @@ namespace IM_API
|
||||
policy.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyOrigin();
|
||||
.AllowCredentials()
|
||||
.SetIsOriginAllowed(origin =>
|
||||
{
|
||||
// 允许所有来自本地或特定网段的请求
|
||||
var host = new Uri(origin).Host;
|
||||
return host == "localhost" || host.StartsWith("192.168.");
|
||||
});
|
||||
});
|
||||
});
|
||||
//凭证处理
|
||||
@@ -86,11 +92,7 @@ namespace IM_API
|
||||
context.Token = accessToken;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
};
|
||||
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
},
|
||||
OnAuthenticationFailed = context =>
|
||||
{
|
||||
Console.WriteLine("Authentication failed: " + context.Exception.Message);
|
||||
|
||||
Reference in New Issue
Block a user