Session variable in C# file (not code behind) with SignalR

onglider

New Member
I am trying to use SignalR, which I am fairly sure I have right. What I am doing is trying to fire off a server side method at an interval using SignalR client -> server calls. In the server side method I have a condition that the Session["User"] must not be null, which it cannot possibly be null at the time this method fires because it fires from a control once that control is loaded. However, I am getting a null exception when the method is called on this condition none the less. here is the C# server side code:\[code\][HubName("timer")]public class Timer : Hub{ public void Time() { QueryFactory qFactory = new QueryFactory(); if (HttpContext.Current.Session["User"] != null) { var ui = (UserInfo)HttpContext.Current.Session["User"]; var userId = ui.UserID; var userName = ui.Name; var serverName = Dns.GetHostName(); if (!userName.Equals("")) { var query = qFactory.GetQuery("P_UPDATE_CURRENT_USER"); query["userid_in"] = Int32.Parse(userId); query["last_changed_in"] = DateTime.Now; query["server_name_in"] = serverName; query.Execute(); } } }}\[/code\]here is the client side code that is calling the server side:\[code\]$(function () { var hub = $.connection.timer; if (<%=Session["User"]%> !== null) { alert(<%=Session["User"]%>); $.connection.hub.start().done(function() { setInterval(function() { hub.server.time(); }, <%=ConfigurationManager.AppSettings["timerInterval"]%>); }); }});\[/code\]notice that in the client side script I put an alert out to fire BEFORE the server side method is called and this alert returns a session user value so I know the session is valid before this call happens. Any ideas why this null error is happening?
 
Back
Top