asp.net中使用uploadify插件上传文件, session中的值丢失的问题

工作中遇到使用uploadify插件上传文件后,后台代码中的session[XXX]值为null的问题,反复跟踪,发现不是值丢失,而是sessionID发生了变化,而引起SessionID发生变化的原因就是因为使用了uplodify插件

解决方法:

<script type="text/javascript">
var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ?
string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
var ASPSESSID = "<%= Session.SessionID %>";

$("#uploadifyLogo").uploadify({
...
formData: { ASPSESSID: ASPSESSID, AUTHID: auth }
});
</script>

Global.asax 文件
protected void Application_BeginRequest(object sender, EventArgs e)
{
/* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */
try
{
string session_param_name = "ASPSESSID";
string session_cookie_name = "ASP.NET_SessionId";

if (HttpContext.Current.Request.Form[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
}
else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
}
}
catch { }

try
{
string auth_param_name = "AUTHID";
string auth_cookie_name = FormsAuthentication.FormsCookieName;

if (HttpContext.Current.Request.Form[auth_param_name] != null)
{
UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
}
else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
{
UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
}
}
catch { }
}

private void UpdateCookie(string cookie_name, string cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
if (null == cookie)
{
cookie = new HttpCookie(cookie_name);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);
}

原文地址:

https://www.cnblogs.com/xust/articles/3522367.html

http://stackoverflow.com/questions/1729179/uploadify-session-and-authentication-with-asp-net-mvc

原文地址:https://www.cnblogs.com/spaceMM/p/12343990.html

时间: 2024-12-18 19:14:56

asp.net中使用uploadify插件上传文件, session中的值丢失的问题的相关文章

使用uploadify组件上传文件

uploadify是和jQuery结合使用的异步上传组件,主要功能是批量上传文件,使用多线程来上传多个组件. 下载并导入js和样式文件 在正式学习uploadify组件之前,首先就是去官网下载最新的js和css等. http://www.uploadify.com/download/ 解压后如图:上面使用红色标示的文件是需要引入到项目中的.另外别忘了引入jquery.js文件 html页面以及上传条件的编写 <html> <head> <base href="<

asp.net mvc ajax.beginform()无法上传文件

Asp.Net Mvc使用Ajax.BeginForm上传文件Request.Files始终为null. 使用jquery.form.js插件能解决问题.asp.net mvc ajax.beginform()无法上传文件

java配置ueditor中解决“未找到上传文件”错误提示

ueditor是一个功能十分强大的在线文本编辑器,但是在ssh框架中,确切的说实在struts2中由于其拦截器需要对request,session对象进行重新封装,这个过程中会把request对象中保存的一些内容清空,所以会导致ueditor的上传功能获取不到需要上传的内容导致“未找到上传文件”的错误! 参考网上资料和自己实验,最终的解决思路是,重写struts2中的一个转换的类,然后配置struts2使用我们重写的这个类.由于我们的工程中可能会有其他的上传等功能,为了不影响其他功能的时候,还需

node.js+react全栈实践-Form中按照指定路径上传文件并

书接上回,讲到“使用同一个新增弹框”中有未解决的问题,比如复杂的字段,文件,图片上传,这一篇就解决文件上传的问题.这里的场景是在新增弹出框中要上传一个图片,并且这个上传组件放在一个Form中,和其他文本字段一起提交给接口. 这里就有几个要注意的问题: 图片上传时最好能在前端指定图片类型,根据这个类型上传到指定的目录.比如这里是新增用户,上传用户图片,那么这里就指定类型是“user”,那么就把这个文件上传到服务器的upload/user目录中.这样方便后期维护,比如要把项目中的文件统一迁移到另外一

异步上传文件并获得返回值(完全跨域)

http://blog.csdn.net/lrz1011/article/details/7913992 异步上传文件并获得返回值(完全跨域)AJAX可以进行数据的异步请求,但对于文件和跨域问题却束手无策. Jsonp可以进行跨域数据的异步请求,但同样不能使用于文件. <form>表单可以进行跨域数据和文件的上传,但却会使页面跳转. 那么如何同时实现“异步”+“跨域”+“文件”+“返回值”这几个特性呢?方法如下: 原理: 将<form>表单通过一个iframe来submit,也就是

解决swfupload上传文件session失效

使用flash插件上传,可能是很多人选择的方式,但是随之而来的session丢失问题也着实让人头疼 swfupload代码如下: <script type="text/javascript" src=\'#\'" echo base_url();?>/static/js/swfupload/swfupload/swfupload.js"></script> <script type="text/javascript&qu

php 上传文件 $_FILES[&#39;&#39;][&#39;type&#39;]的值

php 上传文件 $_FILES['']['type']的值 一个函数 function upload_file($fname,$ftype,$fsize,$ferror,$ftmp_name,$fpath){ date_default_timezone_set('PRC'); $store_nm = date("YmdHis") . "-" . rand(10000,99999) . "-". strlen($fname)."-$fn

【要什么自行车】ASP.NET MVC4笔记02:上传文件 uploadify 组件使用

参考:http://www.cnblogs.com/luotaoyeah/p/3321070.html 1.下载 uploadify 组件,copy至 Content文件夹 <link href="~/Content/uploadify/uploadify.css" rel="stylesheet" /> <script src="~/Content/uploadify/jquery.uploadify.js"></

完整uploadify批量上传文件插件使用

1.首先准备uploadify的js文件,网上一搜一大堆 2.上传页面UpFilePage.aspx 关键代码: <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <tit