
在使用uploadify插件上传文件后,我遇到了后台代码中的会话[XXX]值为空的问题. 我反复跟踪,发现不是丢失的值,而是sessionID更改,这导致SessionID更改的原因是由于使用了uplodify插件
解决方法:
<脚本类型=“文本/ javascript”>
var auth =“ <%= Request.Cookies [FormsAuthentication.FormsCookieName] ==空吗?
string.Empty: Request.Cookies [FormsAuthentication.FormsCookieName] .Value%>“;
var ASPSESSID =“ <%= Session.SessionID%>”;
$(“#uploadifyLogo”). uploadify({
...
formData: {ASPSESSID: ASPSESSIDuploadify 调用2次,AUTHID: auth}
});
script>

Global.asax文件
受保护的无效Application_BeginRequest(对象发送者,EventArgs e)
{
/ *我们估计此时会话尚未被应用程序检索uploadify 调用2次,因此我们重新创建具有会话ID的cookie ... * /
尝试
{
string session_param_name =“ ASPSESSID”;
string session_cookie_name =“ ASP.NET_SessionId”;
如果(HttpContext.Current.Request.Form [session_param_name]!= null)
{
UpdateCookie(session_cookie_name,HttpContext.Current.Request.Form [session_param_name]);

}
否则(HttpContext.Current.Request.QueryString [session_param_name]!= null)
{
UpdateCookie(session_cookie_name,HttpContext.Current.Request.QueryString [session_param_name]);
}
}
抓住{}
尝试
{
string auth_param_name =“ AUTHID”;
字符串auth_cookie_name = FormsAuthentication.FormsCookieName;

如果(HttpContext.Current.Request.Form [auth_param_name]!= null)
{
UpdateCookie(auth_cookie_name,HttpContext.Current.Request.Form [auth_param_name]);
}
否则,如果(HttpContext.Current.Request.QueryString [auth_param_name]!= null)
{
UpdateCookie(auth_cookie_name,HttpContext.Current.Request.QueryString [auth_param_name]);
}
}
抓住{}
}

私有无效UpdateCookie(字符串cookie_name,字符串cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
如果(null == cookie)
{
cookie =新的HttpCookie(cookie_name);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);
}
原始地址:
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-154452-1.html
既然美国不承认十二海里只承认三海里拍几艘核潜艇到美国三海里以外溜达溜达看看美国什么反应
#fx_4walls#
说白了预调酒只有新鲜度