mercredi 31 décembre 2014

Null exception on HttpContext.Current.Request.Cookies when firing SignalR method

Vote count:


First of all Happy new year to all! I shouldn't really be thinking about code today haha. I'm having an odd issue that I cannot seem to figure out or even understand properly.

(Sorry about the formatting, Couldn't get the editor to work - seemed to incorrectly format the code. Please feel free to edit this!)

Basically I have a basic Authorisation method that fetches a security token (cookie) and compares it to the currently logged on user. When firing this from a SignalR method it throws a null exception but I know the user has security token. This works fine without SignalR.

I'll provide code etc..To help understand the problem.

The Architecture:

  1. Business Layer

  2. Presentation Layer

    //Located within the business layer public static User getUserBySecurityToken() { string securityToken = ""; if (HttpContext.Current.Request.Cookies["SecurityToken"] != null) { securityToken = HttpContext.Current.Request.Cookies["SecurityToken"].Value.ToString();


    return user;

    //Located within the presentation layer (hubs) public void Arrange(int tid, string status, string content) { //Get logged on user Business.User user = Business.User.getUserBySecurityToken(); if (user != null) { Clients.Group(user.campaignName).changeTicket(tid, status, content); }


    //Located within the presentation layer (client side script) $(document).on('click', '.move-option-js', function (e) { //This does not even get called due to cookie being null window.hubReady.done(function () { panelHub.server.arrange(i, s, content); }); });

Please note I have omitted some code for the readability. I hope I could get a better understanding of this problem and maybe slightly re-factor the code to get it working.

asked 16 secs ago

Null exception on HttpContext.Current.Request.Cookies when firing SignalR method

Aucun commentaire:

Enregistrer un commentaire