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);
}
}

如果有表单验证,请继续查看http://stackoverflow.com/questions/14465314/how-to-access-session-in-aspx-that-was-modified-in-ashx#comment20148862_14465314

[asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)的更多相关文章

  1. ASP.NET ASHX中获得Session

    有时候需要在ASHX中获取Session,可是一般是获取不到的,如何解决? 1-在 aspx和aspx.cs中,都是以Session["xxx"]="aaa"和 ...

  2. ashx中session的使用

    在平常的页面上是用是很容易就的到request,response对像,从而对其进行一些操作,但在ashx(一般处理程序)中却是有一点的不同, 在ashx你无法正常的使用session,即 contex ...

  3. 转载ASP.NET MVC中Session的处理机制

    本文章转载自 http://www.cnblogs.com/darrenji/p/3951065.html ASP.NET MVC中的Session以及处理方式   最近在ASP.NET MVC项目中 ...

  4. C#使用一般处理程序(ashx)中session

    .ashx中引用 session必须 using System.Web.SessionState ,继承IReadOnlySessionState/IRequiresSessionState IRea ...

  5. Asp.Net Core中Session使用

    web程序中,Session是一个无法避开的点. 最近新开项目,打算从开始搭建一个基础的架子,后台用户登录成功后,需要保存session. 新建的asp.net core的模板已经包含了Session ...

  6. 第十六节:Asp.Net Core中Session的使用、扩展、进程外Session

    一. 简介 关于Session的原理可参照Asp.Net版本Session的文章,去查阅. 1. 普通用法 (1).通过Nuget引入[Microsoft.AspNetCore.Http]程序集,Co ...

  7. 将php中session存入redis中

    PHP 的会话默认是以文件的形式存在的,可以配置到 Redis 中,即提高了访问速度,又能很好地实现会话共享! 配置方式如下: 方法一:修改 php.ini 的设置 session.save_hand ...

  8. asp.net MVC 中 Session统一验证的方法

    验证登录状态的方法有:1  进程外Session   2 方法过滤器(建一个类继承ActionFilterAttribute)然后给需要验证的方法或控制器加特性标签 3 :新建一个BaseContro ...

  9. ASP.NET MVC中Session以及处理方式

    转载原地址 http://www.cnblogs.com/darrenji/p/3951065.html

随机推荐

  1. HDU 4386 Quadrilateral(数学啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4386 Problem Description One day the little Jack is p ...

  2. 基于aspectj的aop的操作

    1.引入相关的jar包 2.建两个类 public class Book { public void add(){ System.out.println("add-----------&qu ...

  3. Python多线程学习(一、线程的使用)

    Python中使用线程有两种方式:函数或者用类来包装线程对象. 1.  函数式:调用thread模块中的start_new_thread()函数来产生新线程.如下例: import thread de ...

  4. Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交

    题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...

  5. html基础知识整理

    html 标题 <h1>这是一级标题</h1> <h2>这是二级标题</h2> <h3>这是三级标题</h3> html注释: ...

  6. lua闭包函数

    function createCountdownTimer(second) local ms = second * local function countDown() ms = ms - retur ...

  7. Git Learning Part II - Working locally

    file status life circle basic: modified:   Examples: untracked: unmodified: modified: Git branching ...

  8. 部署TaskBoard

    部署TaskBoard kiswa/TaskBoard: A Kanban-inspired app for keeping track of things that need to get done ...

  9. Virtualbox guest in KDE Neon

    在最新版的KDE Neon里面装VirtualBox客户端工具,折腾了好久,时间紧的时候不得已用共享U盘的方法将就. 之前要么装完关机按钮点了没反应,要么重启进桌面后任务栏消失,再就是进去之后复制东西 ...

  10. 06--C语言数学函数

    在使用C语言数学函数时候,应该在该源文件中使用以下命令行: #include <math.h> 或 #include "math.h",这里的<>跟&quo ...