[asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)
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:
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);
}
}
[asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)的更多相关文章
- ASP.NET ASHX中获得Session
有时候需要在ASHX中获取Session,可是一般是获取不到的,如何解决? 1-在 aspx和aspx.cs中,都是以Session["xxx"]="aaa"和 ...
- ashx中session的使用
在平常的页面上是用是很容易就的到request,response对像,从而对其进行一些操作,但在ashx(一般处理程序)中却是有一点的不同, 在ashx你无法正常的使用session,即 contex ...
- 转载ASP.NET MVC中Session的处理机制
本文章转载自 http://www.cnblogs.com/darrenji/p/3951065.html ASP.NET MVC中的Session以及处理方式 最近在ASP.NET MVC项目中 ...
- C#使用一般处理程序(ashx)中session
.ashx中引用 session必须 using System.Web.SessionState ,继承IReadOnlySessionState/IRequiresSessionState IRea ...
- Asp.Net Core中Session使用
web程序中,Session是一个无法避开的点. 最近新开项目,打算从开始搭建一个基础的架子,后台用户登录成功后,需要保存session. 新建的asp.net core的模板已经包含了Session ...
- 第十六节:Asp.Net Core中Session的使用、扩展、进程外Session
一. 简介 关于Session的原理可参照Asp.Net版本Session的文章,去查阅. 1. 普通用法 (1).通过Nuget引入[Microsoft.AspNetCore.Http]程序集,Co ...
- 将php中session存入redis中
PHP 的会话默认是以文件的形式存在的,可以配置到 Redis 中,即提高了访问速度,又能很好地实现会话共享! 配置方式如下: 方法一:修改 php.ini 的设置 session.save_hand ...
- asp.net MVC 中 Session统一验证的方法
验证登录状态的方法有:1 进程外Session 2 方法过滤器(建一个类继承ActionFilterAttribute)然后给需要验证的方法或控制器加特性标签 3 :新建一个BaseContro ...
- ASP.NET MVC中Session以及处理方式
转载原地址 http://www.cnblogs.com/darrenji/p/3951065.html
随机推荐
- Cocos2d-X直接使用OpenGL接口
Cocos2d-X是基于基于OpenGL ES的2D游戏引擎,所以Cocos2d-X能够直接使用OpenGL接口 首先建立一个Draw类,用于处理OpenGL接口 在Draw.h中加入以下的代码 #i ...
- php中全局变量global和超全局变量$GLOBALS
php中全局变量global和超全局变量$GLOBALS 1.global Global的作用是定义全局变量,但是这个全局变量不是应用于整个网站,而是应用于当前页面,包括include或require ...
- hdoj-- Walking Ant
Walking Ant Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total S ...
- python基本数据类型之列表list
list的基本功能 结果类型 中括号括起来 逗号(,)分割每一个元素 列表中的元素可以是数字,字符串,列表,布尔值所有的都能放 索引,切片 ? 1 2 3 li = [1, 3, 5, " ...
- 大数据学习之路------借助HDP SANDBOX开始学习
一开始... 一开始知道大数据这个概念的时候,只是感觉很高大上,引起了我的兴趣.当时也不知道,这个东西是做什么的,有什么用,当然现在看来也是很模糊的样子,但是的确比一开始强了不少. 所以学习的过程可能 ...
- jbox如果弹不出,放在body里
body> <form id="form1" runat="server"> <script type="text/javas ...
- 初学struts2杂乱笔记
1.在web.xml文件里定义struts2里的一个过滤类org.apache.struts2.dispatcher.FilterDispatcher 2.在src目录下创建struts.xml文件, ...
- [Offer收割]编程练习赛36
逃离单身节 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector&g ...
- How to share memory between services and user processes?
除了必要的InitializeSecurityDescriptor和SetSecurityDescriptorDacl, 内存映射文件名必须GLOBAL开头.
- Java 方法的应用
Java方法可以理解为C#中的函数,都是把复杂的问题简单化,按模块,按功能区分,分别完成各个部分在调用这些方法完成整个功能. 方法的综合练习,猜数字的实现: 代码要求: 生成不重复的4位数字(只有1- ...