© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
xdd

✅ Postman / SignalR

hi, so i have hub
public class ChatHub : Hub
{
    private readonly IApplicationDbContext _db;
    public ChatHub(IApplicationDbContext context)
    {
        _db = context;
    }

    public override async Task OnConnectedAsync()
    {
        await Clients.Caller.SendAsync("loadMessageHistory", _db.Messages.ToList());
        await base.OnConnectedAsync();
    }
}
public class ChatHub : Hub
{
    private readonly IApplicationDbContext _db;
    public ChatHub(IApplicationDbContext context)
    {
        _db = context;
    }

    public override async Task OnConnectedAsync()
    {
        await Clients.Caller.SendAsync("loadMessageHistory", _db.Messages.ToList());
        await base.OnConnectedAsync();
    }
}

is it possible to send data with first connection request?
for do like...
int chatId = // Getting id from body
var chat = _db.Chats.Inclued(c => c.Messages).FirstOrDefault(c => c.Id == chatId);
// var messages = _db.Messages.Where(m => m.ChatId == chatId).ToList();
if(messages != null)
{ 
  await Clients.Caller.SendAsync("loadMessageHistory", chat/messages);
  await base.OnConnectedAsync();
}
else
{
  // Bad connection or smthing like this
}
int chatId = // Getting id from body
var chat = _db.Chats.Inclued(c => c.Messages).FirstOrDefault(c => c.Id == chatId);
// var messages = _db.Messages.Where(m => m.ChatId == chatId).ToList();
if(messages != null)
{ 
  await Clients.Caller.SendAsync("loadMessageHistory", chat/messages);
  await base.OnConnectedAsync();
}
else
{
  // Bad connection or smthing like this
}

or maybe there is some conventional way to do that
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

SignalR
C#CC# / help
11mo ago
✅ SignalR
C#CC# / help
13mo ago
Signalr
C#CC# / help
15mo ago
SignalR
C#CC# / help
2y ago