我们将所有应用程序会话存储到Global类中。如何正确地将应用程序会话存储到静态实例中?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace MyApp
{
[Serializable]
public class AppSession : IRequiresSessionState
{
//Name that will be used as key for Session object
private const string SESSION_SINGLETON = "MyappSession";
string _UserName;
int? _UserID ,_ClientID;
public int? UserID
{
get
{
return _UserID;
}
set
{
_UserID = value;
}
}
public string UserName
{
get
{
return _UserName;
}
set
{
_UserName = value;
}
}
public int? ClientID
{
get
{
return _ClientID;
}
set
{
_ClientID = value;
}
}
public MarketingSession Marketing { get; set; }
}
}
我们已经创建了另一个类属性来维护网页会话到不同MarketingSession
类,如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace MyApp
{
[Serializable]
public class MarketingSession : IRequiresSessionState
{
private int? _ChannelId;
public int? ChallelId { get
{
return _ChannelId; }
set { _ChannelId = value; }
}
}
}
我不是100%肯定这是它维持会话类或不正确的方法。 和可以在此会话中创建非静态的另一个Class对象吗?
当我添加MarketingSession
Class属性时出现以下错误。
错误10的对象引用需要非静态字段, 方法或属性
MyApp.AppSession.Marketing.get
更新我,如果我做来管理我的应用程序会话或不正确的方式? 如果方法是正确的,那么如何解决这个错误?
显示在您初始化MarketingSession对象的代码。 –
不在AppSession类中初始化。我会改正方式吗?我应该在AppSession类的MarketingSession属性中使用静态成员吗? –
MyApp.AppSession.Marketing.get - 您正在使用此方法,就好像它是静态的。你需要在访问它的属性之前初始化你的AppSession对象,或者首先声明它们是静态的。 –