0

I want to access session value on my hub class

My jquery code is as below

var con = $.connection.MyHub;
$.connection.hub.start().done(function () {
            con.server.send().done(function (data) {
                displayservices(data);    
            })
        })

con.client.addmessege = function (data) {
            displayservices(data);
            //alertSound();
        };

My hub class is as bellow

public Class MyHub : Hub
{
    public void send(string msg)
    {
      client.all.addmessage(msg)
    }
}

How can I access session value in my hub class

Jayaraj.K
  • 928
  • 9
  • 30
osama_1200
  • 29
  • 9
  • Please try this http://stackoverflow.com/questions/621549/how-to-access-session-variables-from-any-class-in-asp-net – Jayaraj.K Jun 30 '16 at 12:31

1 Answers1

-3

You can get the current session from HttpContext, like this:

var sessionVar = HttpContext.Current.Session["SessionVar"];
  • 2
    I know this is several months old, but this does not work. SignalR vers 2 removed Session access from the Hub object. – Wizaerd Oct 20 '16 at 19:25
  • @Wizaerd - In .Net Core 3.1, you can access the Session using Context.GetHttpContext().Session from inside the Hub class. – dcp Aug 20 '20 at 17:00