在Proc会话状态是在两个阶段abadone:当Wroker进程回收或会话超时。状态服务器缺点
我需要保持敏感的会话变化,应用程序依赖于它的存在。 所以我做了两件事。
1-建立会话超时>表单认证超时。
2-使用状态服务器。使用状态服务器导致性能问题,所以我使用缓存来提高性能。
这是CRM应用程序的一部分,其中员工搜索客户时,发现客户被加载到会话状态,然后当员工导航到任何页面时,所有页面都知道我们谈论的是哪个客户。我认为这种方法比使用加密的QueryStrings更好。
你觉得怎么样?有什么我想念的吗?
有没有更好的pradigm可以帮助其他建筑更多?
感谢
public class ContextManager : Manager
{
private static Customer m_Customer;
public static void LoadCustomer(int customerID)
{
if (customerID <= 0)
{
throw new ArgumentException("customer id should be >= 0");
}
m_Customer = CustomerManager.FindCustomerByID(customerID);
HttpContext.Current.Session["Customer"] = m_Customer;
}
public static Customer Customer
{
get
{
if (m_Customer == null) // for performance. the code visit this place very frequently in one http request
{
CheckCustomerInSession();
m_Customer = HttpContext.Current.Session["Customer"] as EdaraFramework.DOC.Customer.Customer;
}
return m_Customer;
}
}
private static void CheckCustomerInSession()
{
if (HttpContext.Current.Session["Customer"] == null)
{
// Pages accepted to have a null customer are default page and customer Search
// , Customer Edit is where LoadCustomer is called.
if ((!HttpContext.Current.Request.Path.Contains("Default.aspx"))
&& (!HttpContext.Current.Request.Path.Contains("CustomerSearch.aspx")))
{
m_Customer = null;
HttpContext.Current.Response.Redirect("~/Default.aspx");
}
}
}
}
我怎么想的,我编辑帖子,谢谢 – Costa
缓存也是用户之间共享。图片我们是您的应用程序的2个用户。我想编辑客户“George”,您正在编辑客户“Sally”。我把客户乔治放在Cache中。然后用“Sally”覆盖“George”。我的网页认为我仍在编辑George,所以我将所有更改保存到“Sally”。您通过使用静态字段和缓存添加了额外的竞争条件。 – MatthewMartin
但我使用客户ID作为关键。 – Costa