如何在asp.net中全局使用列表值c#

hud*_*hab 2 c# asp.net list

我想list在我的aspx页面中全局使用以下名称lstUMSGroupDetails.目前我从一个函数中获取它的价值.

我也希望在其他函数中使用该列表值.那我应该如何让它全球化.

它的代码如下

private void Get_AuthenticateUser_Ums(string strUName)
    {
        string strCurrentGroupName = "";
        int intCurrentGroupID = 0;
        try
        {
            if (!string.IsNullOrEmpty(strUName))
            {
                List<IPColoBilling.App_Code.UMS.UMSGroupDetails> lstUMSGroupDetails = null;
                List<IPColoBilling.App_Code.UMS.UMSLocationDetails> lstUMSLocationDetails = null;                   
                objGetUMS.GetUMSGroups(strUserName, out strCurrentGroupName, out intCurrentGroupID, out lstUMSLocationDetails, out lstUMSGroupDetails);

                if (strCurrentGroupName != "" && intCurrentGroupID != 0)
                {   
                    strCurrentGrp = strCurrentGroupName;                        
                    intCurrentGrpId = intCurrentGroupID;                       

                }
                else
                {
                    Response.Redirect("~/NotAuthorize.aspx", false);
                }
            }
        }
        catch (Exception ex)
        {
            string strErrorMsg = ex.Message.ToString() + " " + "StackTrace :" + ex.StackTrace.ToString();
            CommonDB.WriteLog("ERROR:" + strErrorMsg, ConfigurationManager.AppSettings["IPCOLO_LOG"].ToString());
        }
Run Code Online (Sandbox Code Playgroud)

hab*_*bib 6

你可以存储它Session.

Session["lstUMSGroupDetails"] = lstUMSGroupDetails;
Run Code Online (Sandbox Code Playgroud)

然后你可以得到这个.

List<IPColoBilling.App_Code.UMS.UMSGroupDetails> lstUMSGroupDetails = (List<IPColoBilling.App_Code.UMS.UMSGroupDetails>)Session["lstUMSGroupDetails"];
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅MSDN参考.

  • @BNN`会话`用于存储用户会话数据,正是您所要求的.你为什么要寻找别的东西?也许你想问的真正问题是不同的? (2认同)