[asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)
2014-08-10 11:44
471 查看
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:
Add to: Global.asax:
如果有表单验证,请继续查看http://stackoverflow.com/questions/14465314/how-to-access-session-in-aspx-that-was-modified-in-ashx#comment20148862_14465314
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:
void Application_BeginRequest(object sender, EventArgs e) { try { string session_param_name = "ASPSESSID"; string session_cookie_name = "ASP.NET_SESSIONID"; string session_value = Request.Form[session_param_name] ?? Request.QueryString[session_param_name]; if (session_value != null) { UpdateCookie(session_cookie_name, session_value); } } catch (Exception) { } } void UpdateCookie(string cookie_name, string cookie_value) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name); if (cookie == null) { HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value); Response.Cookies.Add(cookie1); } else { cookie.Value = cookie_value; HttpContext.Current.Request.Cookies.Set(cookie); } }
如果有表单验证,请继续查看http://stackoverflow.com/questions/14465314/how-to-access-session-in-aspx-that-was-modified-in-ashx#comment20148862_14465314
相关文章推荐
- 在ASP.NET中使用IHttpHandler处理请求(如自实现AJAX)时,无法获得Session(或者说是Session 为 null)的原因及解决方法
- asp.net中,在.ashx文件中使用Session
- asp.net .ashx一般处理程序中使用Session
- ASP.NET的ASHX一般处理程序中Session为null且不能赋值
- ASP.NET的ASHX一般处理程序中Session为null且不能赋值
- 【ASP.NET】利用.ashx、Ajax、Session优化Repeater的使用
- 【转】[ASP.NET]使用jQuery的Ajax存取資料(ashx,aspx,asmx)
- 转】[ASP.NET]使用jQuery的Ajax存取資料(ashx,aspx,asmx)
- ASP.NET一般处理程序(.ashx.cs)中使用Session的问题
- ASP.NET在.ashx文件中使用session出异常,未将对象引用到对象的实例。
- 在ASP.NET的.ashx(General Handler)文件中使用Session
- ASP.NET在.ashx文件中使用session出异常,未将对象引用到对象的实例
- ASP.NET的ASHX一般处理程序中Session为null且不能赋值
- ASP.NET的ASHX一般处理程序中Session为null且不能赋值
- 使用ASP.NET制作的FLASH04-MSDN在线阅读器
- Asp.net 默认配置下,Session莫名丢失的原因及解决办法
- asp.net中application,cookies,stateview,session的使用
- 在ASP.NET中使用Session常见问题集锦
- 在ASP.NET中使用Session常见问题集锦
- asp.net的session使用