C# 如何在mvc中为会话创建类
我是MVC的新手。。如何为这样的会话创建类。。 抽象会话类中属性的存储。。请用正确的方法帮助我。。提前多谢C# 如何在mvc中为会话创建类,c#,asp.net-mvc,session,C#,Asp.net Mvc,Session,我是MVC的新手。。如何为这样的会话创建类。。 抽象会话类中属性的存储。。请用正确的方法帮助我。。提前多谢 public interface Isession { string CurrentUserName(); string CurrentUserPassword(); string CurrentUserProfile(); string CurrentUserLanguage(); void ClearAllSession(); } public
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{
??
}
}
单个属性的示例
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
}
}
请参阅。这里我有一个MVC的好例子:会话变量@纳文库马尔,谢谢!但是你可能想把它作为对问题的一个评论:-)如果我有10个会话道具,意味着我必须提及其中的所有内容??ClearAllSession(){CurrentUser=null;//和其他道具}是的,你必须提到所有。。。