Состояние Proc Session State отсутствует в двух случаях: когда Wroker Process Recycling или когда время ожидания сеанса.
Мне нужно хранить конфиденциальные переменные сессии, где приложение зависит от его существования.
Итак, я сделал две вещи.
1- Сделать тайм-аут сеанса> Тайм-аут аутентификации формы.
2 - использовать State Server. Использование State Server вызвало проблемы с производительностью, поэтому я использовал Cache для повышения производительности.
Это часть приложения CRM, где сотрудник ищет клиента, когда найден, клиент загружается в состояние сеанса, затем, когда сотрудник переходит на любую страницу, все страницы знают, о каком клиенте мы говорим. Я думаю, что этот подход лучше, чем использование зашифрованных строк QueryStrings.
Что ты думаешь? Что-то мне не хватает?
Есть ли лучшая парадигма, которая больше помогает остальной части архитектуры?
Спасибо
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");
}
}
}
}