如何从HttpContext.Current.Session [“ PaTSUA”]获取特定值,其中包含值列表

时间:2019-04-11 13:38:18

标签: c# httpcontext

我想从一个会话变量中选择一个特定的值。我如何从本次会议中获得该价值

var tz = HttpContext.Current.Session["PaUA"];

这是我正在使用的代码。当我在即时窗口中执行此操作时,它会显示如下结果

{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"

但是我不知道如何从该结果中获取TimeZone

2 个答案:

答案 0 :(得分:2)

最简单的方法是这样:

 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; }
    }

为您服务:

var tz = HttpContext.Current.Session["PaUA"];
var xx = (dynamic)tz;
var zone = tz.TimeZone;

答案 1 :(得分:0)

只需转换为UA类;

var tz = (PS.UserInterface.Models.UA)HttpContext.Current.Session["PaUA"];
var timezoneValue= tz.TimeZone;