代码之家  ›  专栏  ›  技术社区  ›  hud

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

  •  2
  • hud  · 技术社区  · 6 年前

    我想用下面的 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());
            }
    
    2 回复  |  直到 6 年前
        1
  •  6
  •   habib    6 年前

    你可以把它储存在 Session

    Session["lstUMSGroupDetails"] = lstUMSGroupDetails;
    

    那你就可以把这个拿过来。

    List<IPColoBilling.App_Code.UMS.UMSGroupDetails> lstUMSGroupDetails = (List<IPColoBilling.App_Code.UMS.UMSGroupDetails>)Session["lstUMSGroupDetails"];
    

    MSDN Reference .

        2
  •  1
  •   Emcrank    6 年前

    你不能把它分配给会话字典中的一个槽吗?

    var myList = new List<int>();
    Session["groups"] = myList;