בעיית Session.SessionID ב-global.as

grip23

New member
בעיית Session.SessionID ב-global.as

היי, יש לי בעיית קריאה של Session בתוך PreRequestHandlerExecute של ה-global.asax שאני שובר על זה מעט זמן את הראש.. בכל קריאה ל-session מתקבלת הודעה: session state is not available in this context ??
 

Justin Angel

New member
קה פרובלמה מואי צ'יקיטה?

אכן יש גישה למאפייני ה-Session בשלב ה-PreRequest. הבעיה טמונה בכך שלחלק מהבקשות (למשל בקשות ל-WebResource.axd או בקשות לקבצי *.asmx) אין גישה לנתונים האלו בכלל או בשלב-זה. שימוש ב-Validatorים למשל יגרור הפנייה ל-WebResource.axd (בכדי להשיג את הסקריפט צד לקוח לוולידטורים) ובבקשה מסוג זה אין Session. ולכן, תמיד צריך לבדוק לפני שניגשים ל-Session בכל מיני מקומות ב-Http Pipeline שבאמת קיים Session.
// for writing to session somewhere in HttpPipeline if (Context.Handler is IRequiresSessionState) Session["foo"] = "hello world!"; // for read-write if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState) string myFoo = Session["foo"].ToString();​
 
למעלה