如何创建一个类的会话在mvc

本文关键字:mvc 一个 会话 何创建 创建 | 更新日期: 2023-09-27 17:52:52

我是MVC新手。如何为这样的会话创建类…抽象Session类中属性的存储。请以正确的方式帮助我。提前谢谢你

public interface Isession {
    string CurrentUserName();
    string CurrentUserPassword();
    string CurrentUserProfile();
    string CurrentUserLanguage();
    void ClearAllSession();
}
public class Session:Isession {
    Public static string CurrentUserName{
        get ....?
        set...?
    }
    Public static string CurrentUserPassword{
        get ....?
        set...?
    }
    Public static string CurrentUserProfile{
        get ....?
        set...?
    }
    Public static string CurrentUserLanguage{
        get ....?
        set...?
    }
    Public Static Void ClearAllSession{
    ??
    }
}

如何创建一个类的会话在mvc

单个属性的示例。

public class Session : ISession {
    private const string CURRENTUSERKEY = "CurrentUser";
    public static string CurrentUser {
        get { return (string)HttpContext.Current.Session[CURRENTUSERKEY]; }
        set { HttpContext.Current.Session[CURRENTUSERKEY] = value; }
    }
    public static void ClearAllSession() {
        CurrentUser = null; // And the other props
    }
}