我有一个用 asp.net mvc2 编写的 Web 应用程序。目前托管在亚马逊云 ec2 上。由于流量不断增长,我们希望移动多实例环境。我有一个自定义会话类,它当前在会话开始时启动(全局 asax),我通过应用程序中的 getter 或 setter 类使用。由于多实例杂务,我必须处理漏洞安全架构。我正在寻找一种更好的方法来处理这个问题。
protected void OnSessionStart()
{
HttpContext.Current.Session.Add("mySessionObject", new MyAppSession());
}
public static MyAppSession GetMySessionObject(HttpContextBase current)
{
if (current != null)
{
if (current.Session != null)
if (current.Session["mySessionObject"] == null)
{
current.Session.Add("mySessionObject", new MyAppSession());
}
}
if ( current != null && current.Session != null)
return (MyAppSession ) (current.Session["mySessionObject"]);
return null;
}
and so on.