Question

I am currently in the process of sketching-out an application that allows real-time interactions with website visitors.

Therefore, I have two different "User-types":

  1. Unregistered User: these are the visitors
  2. Registered User: these have a (custom) ASP.NET MVC membership

Now, I am persisting "UserNames" and ConnectionIds in a DB so I can freely scale at some point in the future. I do this by accessing Context.Identiy.User.UserName from within the Hub and then query the DB for any existing "sessions".

Here is the problem:

  1. I need two different types of "User"
    1. For one, I want to dynamically generate a GUID - these are the visitors and will be removed from the database after a given amount of inactivity.
    2. These are the admins, they have their proper identities attached to the Context object.

So, how would one go about accessing a "session" from SignalR? It is not really a Session, I just need to get a SessionId from a Cookie on each initial request to the MVC-Controller, that's all. All I need to be able to do is:

  1. Have an auto-generated "SessionId" which I can use to persist visitors across requests
  2. Have a more "extended" identity: I want to use UserId instead of UserName

Anyway, I hope this makes sense but chip in if anything is unclear.

Was it helpful?

Solution

Okay, I just realised that I can use "HttpContext.Current.Request.AnonymousId" and I am linking this up to a Session-database.

Here some relevant documentation: http://msdn.microsoft.com/en-us/library/system.web.httprequest.anonymousid.aspx

This solved my problem in this case. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top