mdevilliers / SignalR.RabbitMq

MessageBus implementation using RabbitMq as the backing store.
MIT License
89 stars 40 forks source link

HttpContext.Current is null #25

Closed jchannon closed 10 years ago

jchannon commented 10 years ago

Hi!

In your hub example https://github.com/mdevilliers/SignalR.RabbitMq/blob/master/SignalR.RabbitMQ.Example/Chat.cs if you add

public override Task OnConnected()
{
    var s = HttpContext.Current;

    return base.OnConnected();
}

HttpContext.Current is null.

If you take out GlobalHost.DependencyResolver.UseRabbitMq(configuration); in Global.asax and run the app up then its no longer null.

The issue I have with this is when I use OnConnected in my app I add users to a group. The name of the group is determined by an extension method I have on HttpContext.Current

public override Task OnConnected()
{
    string name = HttpContext.Current.GetMyAppUserId().ToString();

    Groups.Add(Context.ConnectionId, name);

    return base.OnConnected();
}

Is this a bug or something dumb I am not understanding?

jchannon commented 10 years ago

Turns out I can use Context.User as a property on the hub and make my GetMyAppUserId method public so i can access it and it all works

danbarua commented 10 years ago

@jchannon PEBKAC

jchannon commented 10 years ago

:p

mdevilliers commented 10 years ago

Cool - so are you good?

jchannon commented 10 years ago

Yup think so, don't understand why Current is null though

timc13 commented 10 years ago

HttpContext.Current is not initiated in the context of Signal R. I believe you can use Context.Request.GetHttpContext()

mdevilliers commented 10 years ago

I think Tim is correct, also confirmed by the dfowler it looks like this can't be relied on to be there.