我将所有直接会话交互分离到一个单独的类中并使其成为静态,因为我不想多次创建新对象。但是,我希望确保没有并发问题或其他奇怪的惊喜。
这是代码:
public static class HttpHelper
{
    public static string Get(string key)
    {
        object value = HttpContext.Current.Request.QueryString[key];
        return (value == null) ? null : value.ToString();
    }
    public static string Post(string key)
    {
        object value = HttpContext.Current.Request.Form[key];
        return (value == null) ? null : value.ToString();
    }
    public static string Session(string key)
    {
        object value = HttpContext.Current.Session[key];
        return (value == null) ? null : value.ToString();
    }
    public static void ClearSession(string key)
    {
        HttpContext.Current.Session[key] = null;
    }
    public static void StoreInSession(string key, object value)
    {
        HttpContext.Current.Session[key] = value;
    }
}