Reputation: 575
I want to select a particular value from a session variable. How can I get that value from this session
var tz = HttpContext.Current.Session["PaUA"];
this is the code I am using. When I execute this in the immediate window it shows the result like this
{PS.UserInterface.Models.UA}
ApplicationID: {de151484-f822-4692-a36b-e7e1fc1066fe}
CompanyID: {fef3fb8e-365f-4cc4-8976-ff9e5ed1516c}
DBConnectionString: "Data Source=WIN-ISPHTIHPJFI\\MSSQLSERVER2016;Initial Catalog=PSDefault;User ID=dba;Password=dba@2018"
DefaultModuleID: {00000000-0000-0000-0000-000000000000}
IsMainContractor: true
LicenseID: {ac258d7d-25dc-44f9-b798-2d4657d68c95}
LicenseType: "MultiUser"
LoginName: "suvaneeth"
LoginTime: "11-Apr-2019 18:39:34"
RolesCSV: "SAAdmin"
ThemeCode: "Liquid"
TimeZone: "Dateline Standard Time"
UserID: {fc938df0-8a4e-4c85-b93c-be51373c559f}
UserName: "Suvaneeth S"
UserProfileID: {fc938df0-8a4e-4c85-b93c-be51373c559f}
UserWeekStartDay: "1"
licenseModuleCSV: "830683B5-6D12-4AF9-AF76-7013A930AA0D,F774DF88-C2D6-4527-8A0E-493E1E1D3120"
But I don't get any idea of how can I get TimeZone from this result
Upvotes: 1
Views: 901
Reputation: 885
Just cast to UA class like;
var tz = (PS.UserInterface.Models.UA)HttpContext.Current.Session["PaUA"];
var timezoneValue= tz.TimeZone;
Upvotes: 0
Reputation: 1664
the easiest way is to do it like this:
static void Main(string[] args)
{
var test = new test { abc = "asdasdasd" };
var xx = (dynamic)test;
Console.WriteLine(xx.abc);
}
class test
{
public string abc { get; set; }
}
so for you:
var tz = HttpContext.Current.Session["PaUA"];
var xx = (dynamic)tz;
var zone = tz.TimeZone;
Upvotes: 2