[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
随机推荐
- Could not read from remote repository.
今天换新电脑,忘了配置git环境,就去gitserver上代替码.然后一直报错,后来就又一次配置了git环境.步骤例如以下 damingwuage:Desktop damingwuage$ ssh-k ...
- luogu4012 深海机器人问题 网络流
关键词:最小费用最大流 题目大意:海底是个网格,每个网格边有一定价值的海底化石.每个路线可经过无限个机器人,但上面的化石只能采一次.机器人可沿网格边向东或向北移动.给定机器人起点和终点位置及所能容纳的 ...
- bootstrap 操作指南
1.table中显示级联类的属性显示 例如:java代码 public class MrTask { private Integer id: private User create_user; } p ...
- C++_class_powerpoint_1.1
Types and Declarations Boolean Type bool type – boolean , logic type bool literal – true, falseint a ...
- JXOI2019 退役记
day0 考前一天在机房和RyeCatcher,还有高一数竞大佬wyt一起颓三国杀,被深深吸引无法自拔,所谓大考大浪,也算是缓解缓解压力 刷刷空间发现好多外地OIer都赶到江科了,萌生出去见一见我江西 ...
- ES6和Node容易搞混淆的点
ES6 import 模块名 from XX '模块标识符' -----导入模块 import '路径 ' -----导入CSS样式 export default { } 和export ...
- c++对象关系映射(ORM)框架
ORM(Object Relational Mapping, 对象关系映射),用来将基于对象的数据结构映射到SQL的数据结构中,即将基于对象的数据映射到关系表中的字段,然后我们可以通过对象提供的接口来 ...
- 控件——DataGridview
控件:DataGridview 用来显示数据, 可以显示和编辑来自多种不同类型的数据源的表格数据. 一.两种显示数据的方式:手动,后台代码 主要通过后台代码:先建立三大类 然后绑定 ...
- Android WindowManager和WindowManager.LayoutParams的使用以及实现悬浮窗口的方法
1.理清概念 我们使用过Dialog和PopupWindow,还有Toast,它们都显示在Activity之上.那么我们首先需要理解的是android中是如何去绘制这些UI的呢?这里我只讲我所理解的, ...
- (到8.1为止)Android版本名称与内容
版本名称 API 主要版本更新时间 Android 1.0 1 测试版本 Android 1.1 2 2008 年9月正式发布的Android第一版 Android 1.5 Cupcake(纸杯 ...