ojek
ojek

Reputation: 10088

ASP.NET MVC - accessing session information from "not connected" class

I am using XSockets. Now, from inside of xsocket controller, I need to access my users data. I tried doing this:

public class SocialsController : XSocketController, Controller

But that is not allowed. Is there a way for me to access all the session data inside my SocialsController?

Upvotes: 0

Views: 161

Answers (1)

Uffe
Uffe

Reputation: 2275

You cant use ASP.NET sessions in XSockets since the server is running outside of the IIS. In the future you might be able to, but not in the current version.

Every connection you create in XSockets has it´s own instance of the controller you connected to. So we have state on the controller, and regular HTTP/ASP.NET MVC does not have state.. Thats why they need sessions.

So what if you refresh/change page in XSockets? You will loose state since the controller will "die"... However, XSockets has it´s own SessionStorage so you can store data on the server for specific clients. This SessionStorage can be accessed both from JavaScript as well as C#.

C# Example storing a Person object, but it can be anything

//Save in storage (will be there even if you disconnect and then reconnect)
this.StorageSet("me",new Person{Name="Uffe", Age=35});
//Get from storage (casting to correct type).
var p = (Person)this.StorageGet("me");

JavaScript

//Setting, but check http://xfiddle.net/XFiddle/ for get, set, delete, getall

var myStorageObject = { Key: 'foo', Value: $("#storeValue").val() };
ws.trigger(XSockets.Events.storage.set, myStorageObject);

Regards Uffe

Upvotes: 2

Related Questions