ASP.Net Session

前端 未结 13 1380
清酒与你
清酒与你 2020-12-08 07:54

I am wanting to store the \"state\" of some actions the user is performing in a series of different ASP.Net webforms. What are my choices for persisting state, and what are

13条回答
  •  甜味超标
    2020-12-08 08:14

    I think using Session object is OK in this case, but you should remember Session can expire if there is no browser activity for long time (HttpSessionState.Timeout property determines in how many minutes session-state provider terminates the session), so it's better to check for value existence before return:

    public static Account GetCurrentAccount(HttpSessionState session)
    {
        if (Session[ACCOUNT]!=null)
            return (Account)Session[ACCOUNT];
        else
            throw new Exception("Can't get current account. Session expired.");
    }
    

提交回复
热议问题