I'm making a web api chat application with user register/login with SignalR, ASP.NET, VS Code in C#. I would like to make an online user counter, which i made in the CounterHub.cs, but I don't know, how can I use in my Welcome.cshtml page. Is it possible to sent integer data from this .CS file to .CSHTML file? Here is my CounterHub.cs file
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading.Tasks;
namespace probagetrequest.Hubs
{
public static class UseHandler
{
public static HashSet<string> ConnectedIds = new HashSet<string>();
}
public class MyHub : Hub
{
public override Task OnConnectedAsync()
{
UseHandler.ConnectedIds.Add(Context.ConnectionId);
return base.OnConnectedAsync();
}
public override Task OnDisconnectedAsync(Exception exception)
{
UseHandler.ConnectedIds.Remove(Context.ConnectionId);
return base.OnDisconnectedAsync(exception);
}
int counting = UseHandler.ConnectedIds.Count;
}
}
I want to call the counting variable in my .cshtml file