Вопрос по session, asp.net-mvc-3, asp.net – ASP.NET MVC - сессия пуста

9

У меня есть приложение MVC3 на .net4, что его сеанс работает в среде разработки, но не в производстве.
В производственном процессе я зарегистрировал sessionID, и он совпадает с моментом, когда я установил и получил из сеанса.

Когда я пытаюсь получить сессию, я получаюNull Exception.

Вот как я получаю доступ к сессии:

public static class HandlersHttpStorage
{
    public static string TestSession
    {
        get
        {
            return HttpContext.Current.Session["time"];//This is null
        }
        set
        {
            HttpContext.Current.Session.Add("time", value);//DateTime.Now.ToString()
        }
    }
}

Что меня беспокоит, так это то, что поведение в производственном процессе отличается от разработки, хотя web.config такой же.

Error: User Rate Limit Exceeded Adam Tuliper - MSFT
Error: User Rate Limit Exceeded Shazam
Error: User Rate Limit Exceeded Adam Tuliper - MSFT
Error: User Rate Limit Exceededstackoverflow.com/a/1212451/578859 Paul

Ваш Ответ

3   ответа
0

Error: User Rate Limit ExceededHttpContext.CurrentError: User Rate Limit Exceeded

System.Web.HttpContext c = System.Web.HttpContext.Current; 

Error: User Rate Limit Exceeded

string myString = "Something to save";
SessionExtensions.SetDataToSession<string>(c, "MyKey1", myString);

Error: User Rate Limit ExceededSessionError: User Rate Limit Exceededthis HttpSessionStateBase sessionError: User Rate Limit ExceededNullReferenceExceptionError: User Rate Limit ExceededSessionError: User Rate Limit Exceeded

public static class SessionExtensions 
{ 
   /// <summary> 
   /// Get value. 
   /// </summary> 
   /// <typeparam name="T"></typeparam> 
   /// <param name="session"></param> 
   /// <param name="key"></param> 
   /// <returns></returns> 
   public static T GetDataFromSession<T>(this HttpSessionStateBase session, string key) 
   { 
       return (T)session[key]; 
   } 
   /// <summary> 
   /// Set value. 
   /// </summary> 
   /// <typeparam name="T"></typeparam> 
   /// <param name="session"></param> 
   /// <param name="key"></param> 
   /// <param name="value"></param> 
   public static void SetDataToSession<T>(this HttpSessionStateBase session, string key, object value) 
   { 
       session[key] = value; 
   } 
} 

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

public static class SessionExtensions 
{ 
   /// <summary> 
   /// Get value. 
   /// </summary> 
   /// <typeparam name="T"></typeparam> 
   /// <param name="session"></param> 
   /// <param name="key"></param> 
   /// <returns></returns> 
   public static T GetDataFromSession<T>(HttpContext context, string key) 
   { 
        if (context != null && context.Session != null)
        {
            context.Session.Abandon();
        }

        return (T)context.Session[key];
   } 
   /// <summary> 
   /// Set value. 
   /// </summary> 
   /// <typeparam name="T"></typeparam> 
   /// <param name="session"></param> 
   /// <param name="key"></param> 
   /// <param name="value"></param> 
   public static void SetDataToSession<T>(HttpContext context, string key, object value) 
   { 
       context.Session[key] = value; 
   } 
} 

Error: User Rate Limit Exceeded

System.Web.HttpContext c = System.Web.HttpContext.Current;
string myString = SessionExtensions.GetDataFromSession<string>(c, "MyKey1");

Error: User Rate Limit ExceededHttpContext.CurrentError: User Rate Limit ExceededSessionError: User Rate Limit Exceeded

 string myString = Session["MyKey1"].ToString();

Error: User Rate Limit Exceeded<string>Error: User Rate Limit ExceededSetDataToSession()Error: User Rate Limit Exceeded

List<string> myStringList = new List<string>();
myStringList.Add("Something to save");
SessionExtensions.SetDataToSession<List<string>>(c, "MyKey1", myStringList);

Error: User Rate Limit Exceeded

System.Web.HttpContext c = System.Web.HttpContext.Current;
List<string> myStringList = SessionExtensions.GetDataFromSession<List<string>>(c, "MyKey1");

Error: User Rate Limit Exceeded

List<string> myStringList = (List<string>)Session["MyKey1"];
15

Solution 1:

Link: Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<configuration>
  ...
  <system.webServer>
    ...
    <modules>
      <remove name="Session" />
      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
      ...
    </modules>
  </system.webServer>
</configuration>

Error: User Rate Limit Exceededmachine.config.

Error: User Rate Limit Exceeded

Solution 2:

Link: Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

HttpContext.Current.Session["CurrentUser"]

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

static readonly string SESSION_CurrentUser = "CurrentUser";

public static SiteUser Create() {     
 SiteUser.Current = new SiteUser();      
 return SiteUser.Current;
}

public static SiteUser Current {     
 get {         
  if (HttpContext.Current.Session == null || HttpContext.Current.Session[SESSION_CurrentUser] == null) {             
   throw new SiteUserAutorizationExeption();         
  }          
  return HttpContext.Current.Session[SESSION_CurrentUser] as SiteUser;     
 } 
 set {
  if (!HttpContext.Current.Session == null) {
   HttpContext.Current.Session[SESSION_CurrentUser] = value;
  }
 }
} 
Error: User Rate Limit Exceeded Shazam

Похожие вопросы