Hello To All,
I have a little problem in getting session id in controller.Session id has not a constant value. its an object having username, password ,firstname but i want to get only username value and store it into a variable.
e.g var test = session["onGoingUser"]
Here , onGoingUser is an object having three values and i want only one value which should be store in test.So how could this possible.Or any other solution except this.
Urgently needed.
How to get Session ID in Controller in MVC 3.0?
Page 1 of 12 Replies - 3199 Views - Last Post: 17 May 2012 - 10:54 PM
Replies To: How to get Session ID in Controller in MVC 3.0?
#2
Re: How to get Session ID in Controller in MVC 3.0?
Posted 17 May 2012 - 06:41 AM
Basically Session is just an object container. when you cast it like you are to var test you're creating an object named test. You will need to tell the compiler to treat this object AS something What is your back end language? are you using VB.NET or C#?
in C# you would do something like this:
This basically says Cast your session object as the object you specify. This is safe because if it can't cast it then you will receive a null back instead of an exception.
in C# you would do something like this:
var test = (Session["onGoingUser"] as <object>);
if(test != null)
{
var value = test.<value>;
}
This basically says Cast your session object as the object you specify. This is safe because if it can't cast it then you will receive a null back instead of an exception.
#3
Re: How to get Session ID in Controller in MVC 3.0?
Posted 17 May 2012 - 10:54 PM
Sorry for late reply brother..backend language is C# ...
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|