asp.net uploadify文件已上传到指定目录,但进度条却显示的是上传失败信息HTTP Error
2015-01-22 16:25
639 查看
问题:
uploadify 多文件上传时,文件已经成功上传到指定目录下,但是进度条却显示上传失败,提示Http Error 错误
造成原因:项目后台有用户登录,用插件uploadfiy上传文件时,造成Session丢失,使原来已经登录的信息在上传的时候,没有传递到服务器。
解决方法:多文件上传时,将session传递到服务器重新写入。
第一步:在使用uploadify插件时,拿出auth和session作为参数传递到服务器。
var auth = "<%=Request.Cookies[FormsAuthentication.FormsCookieName]==nullstring.Empty:Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
var ASPSESSID = "<%=Session.SessionID %>";
![](https://img-blog.csdn.net/20150122161910568?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmFpZHVfMTY2MzUwMDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
第二步:在Global.asax文件的Application_BeginRequest方法重新写入。
protected void Application_BeginRequest(object sender, EventArgs e)
{
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]);
}
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]);
}
}
private void UpdateCookie(string cookie_name, string cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
if (cookie == null)
{
cookie = new HttpCookie(cookie_name);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);//重新设定请求中的cookie值,将服务器端的session值赋值给它
}
重新编译一下,OK 。
uploadify 多文件上传时,文件已经成功上传到指定目录下,但是进度条却显示上传失败,提示Http Error 错误
造成原因:项目后台有用户登录,用插件uploadfiy上传文件时,造成Session丢失,使原来已经登录的信息在上传的时候,没有传递到服务器。
解决方法:多文件上传时,将session传递到服务器重新写入。
第一步:在使用uploadify插件时,拿出auth和session作为参数传递到服务器。
var auth = "<%=Request.Cookies[FormsAuthentication.FormsCookieName]==nullstring.Empty:Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
var ASPSESSID = "<%=Session.SessionID %>";
第二步:在Global.asax文件的Application_BeginRequest方法重新写入。
protected void Application_BeginRequest(object sender, EventArgs e)
{
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]);
}
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]);
}
}
private void UpdateCookie(string cookie_name, string cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
if (cookie == null)
{
cookie = new HttpCookie(cookie_name);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);//重新设定请求中的cookie值,将服务器端的session值赋值给它
}
重新编译一下,OK 。
相关文章推荐
- asp.net Mvc 使用uploadify 上传文件 HTTP 302 Error
- 【转】Asp.NET大文件上传组件开发总结(五)---上传进度信息的显示
- Asp.Net 无刷新文件上传并显示进度条的实现方法及思路
- asp.net中当服务器出错时显示指定的错误页面,同时把错误信息写入系统日志文件
- Asp.Net 无刷新文件上传并显示进度条的实现方法及思路
- Asp.NET大文件上传组件开发总结(五)---上传进度信息的显示
- Asp.net网站发布报错(HTTP 错误 404 文件或目录未找到。Internet 信息服务(IIS)
- Asp.net IO类递归显示目录,文件信息
- Asp.Net 无刷新文件上传并显示进度条的实现方法及思路
- asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)
- asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)
- 【转载】Asp.NET大文件上传组件开发总结(五)---上传进度信息的显示
- asp.net中当服务器出错时显示指定的错误页面,同时把错误信息写入系统日志文件的探讨
- asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)
- c# asp.net uploadify 上传大文件 出现的 HTTP 404 问题
- Asp.net 中,FileUpload 上传文件为何总失败,而 HasFile 为何为 False
- 在Asp.net中如何遍历一个本地目录下的所有文件并上载到Web 服务器上指定的目录中
- asp.net web大文件上传带进度条实例代码
- [ASP.NET]Treeview 控件显示服务端目录文件夹及文件
- asp.net里的上传文件功能(带进度条与进度提示)