使用过Flash上传的同学都知道,Flash有一个Bug
在非IE浏览器下的时候 Session会“丢失” 其实也不算丢失 这里不做详解现在的问题是.
前不久在网上找到了相关解决方案,自己也测试写了个例子。可以成功。
需要添加Global.asax全局应用程序.然而问题来了 在项目中添加Global.asax 这个时候在这个站点下的每个页面应该都会执行
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
这个事件
但是现在的问题是,我从这个站点打开了一个新的连接地址
这个时候调试一下 在打开新的地址中 是不会走刚才那个事件的新的页面正是上传页面 session丢失了 这如何处理?
Global文件有没有办法共享?ASP.NETFlash应用浏览器测试
在非IE浏览器下的时候 Session会“丢失” 其实也不算丢失 这里不做详解现在的问题是.
前不久在网上找到了相关解决方案,自己也测试写了个例子。可以成功。
需要添加Global.asax全局应用程序.然而问题来了 在项目中添加Global.asax 这个时候在这个站点下的每个页面应该都会执行
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
这个事件
但是现在的问题是,我从这个站点打开了一个新的连接地址
这个时候调试一下 在打开新的地址中 是不会走刚才那个事件的新的页面正是上传页面 session丢失了 这如何处理?
Global文件有没有办法共享?ASP.NETFlash应用浏览器测试
而Flash的处理机制又不能将Cookie添加到HttpRequst的标头中 这是Flash的BUG 没有办法
解决办法网上有。目前我遇到的 简而言之就是 我打开新连接地址的页面 相当于又开启了一次回话状态这个时候不知道该怎么去比较两个Seesion值因为解决方案中需要在Gloab文件中处理
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Galsun.Common;
using Galsun.Gzln.Content;
using Galsun.Gzln.Mode;namespace Galsun.Gzln.Web.UI
{
public class Upload : IHttpHandler, IRequiresSessionState
{
gl_MagazineContent _magazine = new gl_MagazineContent();
public Upload()
{ } #region IHttpHandler Members public bool IsReusable
{
get { return true; }
} public void ProcessRequest(HttpContext context)
{
// Example of using a passed in value in the query string to set a categoryId
// Now you can do anything you need to witht the file.
//int categoryId = 0;
//if (!string.IsNullOrEmpty(context.Request.QueryString["CategoryID"]))
//{
// int.TryParse(context.Request.QueryString["CategoryID"],out categoryId);
//}
//if (categoryId > 0)
//{
//} //string temp = context.Session["temp"].ToString();
if (Galsun.Gzln.Global.Current.UserID == "")
{
HttpContext.Current.Response.Write("用户未登陆!");
return;
}
//string EncryptString = context.Request.QueryString["User"];
//FormsAuthenticationTicket UserTicket = FormsAuthentication.Decrypt(EncryptString); if (context.Request.Files.Count > 0)
{
// get the applications path
int docid = DNTRequest.GetInt("docid", 0);
if (docid <= 0)
{
docid = Utils.StrToInt(HttpContext.Current.Session["docid"], -9999);
} string mypath = "/UploadFile/magazine/" + DateTime.Now.ToString("yyyyMM");
string uploadPath = context.Server.MapPath(context.Request.ApplicationPath + mypath);
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
// loop through all the uploaded files
for (int j = 0; j < context.Request.Files.Count; j++)
{
// get the current file
HttpPostedFile uploadFile = context.Request.Files[j];
// if there was a file uploded
if (uploadFile.ContentLength > 0)
{
// save the file to the upload directory //use this if testing from a classic style upload, ie. // <form action="Upload.axd" method="post" enctype="multipart/form-data">
// <input type="file" name="fileUpload" />
// <input type="submit" value="Upload" />
//</form> // this is because flash sends just the filename, where the above
//will send the file path, ie. c:\My Pictures\test1.jpg
//you can use Test.thm to test this page.
//string filename = uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf("\\"));
//uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "Upload\\", filename)); // use this if using flash to upload
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + Galsun.Common.Rand.Number(4) + System.IO.Path.GetExtension(uploadFile.FileName);
uploadFile.SaveAs(Path.Combine(uploadPath, fileName));
gl_magazine_pageinfo info = new gl_magazine_pageinfo();
info.mid = docid;
info.PageNum = j + 1;
info.title = uploadFile.FileName;
info.url = mypath + "/" + fileName;
//info.T_05007 = FormatSize(uploadFile.ContentLength);
_magazine.AddPage(info);
// HttpPostedFile has an InputStream also. You can pass this to
// a function, or business logic. You can save it a database: //byte[] fileData = new byte[uploadFile.ContentLength];
//uploadFile.InputStream.Write(fileData, 0, fileData.Length);
// save byte array into database. // something I do is extract files from a zip file by passing
// the inputStream to a function that uses SharpZipLib found here:
// http://www.icsharpcode.net/OpenSource/SharpZipLib/
// and then save the files to disk.
}
}
}
// Used as a fix for a bug in mac flash player that makes the
// onComplete event not fire
HttpContext.Current.Response.Write(" ");
}
private string FormatSize(int size)
{
if(size < 1024)
return ((size*100)/100).ToString("N0") + " bytes";
if(size < 1048576)
return (((size / 1024)*100)/100).ToString("N0") + "KB";
if(size < 1073741824)
return (((size / 1048576)*100)/100).ToString("N0") + "MB";
return (((size / 1073741824)*100)/100).ToString("N0") + "GB";
} #endregion
}
}//======================================================
//== (c)2008 aspxcms inc by NeTCMS v1.0 ==
//== Forum:bbs.aspxcms.com ==
//== Website:www.aspxcms.com ==
//======================================================
using System;
using System.Web;
using System.Text;
using Galsun.Gzln.Mode;
using Galsun.Gzln.Content;namespace Galsun.Gzln.Global
{
public class Current
{
/// <summary>
/// 帐号
/// </summary>
public static string UserID
{
get
{
return GetInfo().userid;
}
}
/// <summary>
/// 姓名
/// </summary>
public static string UserName
{
get
{
return GetInfo().userName;
}
}
/// <summary>
/// 用户可操作菜单
/// </summary>
public static string UserPower
{
get
{
return GetInfo().power_list;
}
}
/// <summary>
/// 返回用户组信息
/// </summary>
public static gl_usergroupinfo UserGroup
{
get
{
gl_UserGroupContent ug = new gl_UserGroupContent();
return ug.getInfo(GetInfo().group_code);
}
}
/// <summary>
/// 管理范围
/// </summary>
public static int UserRange
{
get
{
return GetInfo().Range;
}
}
/// <summary>
/// 获取客户端IP
/// </summary>
public static string ClientIP
{
get
{
return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
}
public static bool IsTimeout()
{
try
{
gl_userinfo info = new gl_userinfo();
return false;
}
catch
{
return true;
}
}
public static void Set(gl_userinfo info)
{
HttpContext.Current.Session["SITEINFO"] = info;
HttpContext.Current.Session.Timeout = 90;
}
private static gl_userinfo GetInfo()
{
if (HttpContext.Current.Session["SITEINFO"] == null)
throw new Exception("您没有登录系统或会话已过期,请重新登录");
//return (GlobalUserInfo)HttpContext.Current.Session["SITEINFO"];
else
return (gl_userinfo)HttpContext.Current.Session["SITEINFO"]; }
}
}
<add verb="POST,GET" path="Upload.axd" type="Galsun.Gzln.Web.UI.Upload"/>
</httpHandlers>
<FlashUpload:FlashUpload ID="flashUpload" runat="server"
UploadPage="Upload.axd" OnUploadComplete="UploadComplete()"
FileTypeDescription="所有文件(*.*)" FileTypes="*.*"
UploadFileSizeLimit="2000000000" TotalUploadSizeLimit="20000000000" />
查了下 httpmodule 里面可以代替 呵呵 谢谢