[asp.net]ashx中session存入,aspx為null的原因(使用flash uploader)

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   io   strong   

I am using uploadify to upload files, they automatically post to the handler. I then modify the session in the handler that I have setup as a static property in a common class of the website. I then try to access that same session in the aspx page, and the value is null. I have a feeling this is because of cookies, but there needs to be a way to work around this without exposing the sessionid in the url.

 

Solutions

I found the answer: When the handler is being called from FLASH (like swfupload or uploadify) it does not pass the current sessionid to the handler. The handler then creates a NEW session. To fix this, do the following:

$(Selector).uploadify({    swf: ‘uploadify.swf‘,    uploader: ‘Upload.ashx?ASPSESSID=<%=Session.SessionID%>‘   });

Add to: Global.asax:

 1 void Application_BeginRequest(object sender, EventArgs e) 2 { 3     try 4     { 5         string session_param_name = "ASPSESSID"; 6         string session_cookie_name = "ASP.NET_SESSIONID"; 7         string session_value = Request.Form[session_param_name] ?? Request.QueryString[session_param_name]; 8         if (session_value != null) { UpdateCookie(session_cookie_name, session_value); } 9     }10     catch (Exception) { }11 }12 13 void UpdateCookie(string cookie_name, string cookie_value)14 {15     HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);16     if (cookie == null)17     {18         HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value);19         Response.Cookies.Add(cookie1);20     }21     else22     {23         cookie.Value = cookie_value;24         HttpContext.Current.Request.Cookies.Set(cookie);25     }26 }

如果有表單驗證,請繼續查看http://stackoverflow.com/questions/14465314/how-to-access-session-in-aspx-that-was-modified-in-ashx#comment20148862_14465314

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.