问题是这样的,
在第一个页面中:有通过Jquery上传文件的例子
限制上传的速度最高位为每秒钟100kb
然后,每隔一秒种,就会把上传的百分比存到Session中,然后
整个过程在一个while循环中实现。
Session["Process"]="12";
在第一个页面点击上传后,Jquery Ajax开始轮询 另一个 ashx 页面,
通过Response.Write((string)Session["Process"]);然后ajax获取 百分比显示出来。
目前遇到的问题是:
在ashx 中 Session 取值为null
备注:ashx以实现了 相应的接口
- C# code
public class FileUpLoadHandler : IHttpHandler, IRequiresSessionState, IReadOnlySessionState{ public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; //context.Request.Headers.Add("Connection","keep-alive"); Request = context.Request; Response = context.Response; Response.Buffer = false; Response.BufferOutput = false; Server = context.Server; Session=context.Session; string pram=Request.QueryString["process"]; if (pram != null) { if (pram == "true") { Request.ContentType = "text/plain"; Response.ContentType = "text/plain"; object process =Session["Process"]; if (process != null) { Response.Write((string)process); } else { Response.Write("0"); } } } else { UpLoadFiles(); } } HttpRequest Request; HttpResponse Response; HttpServerUtility Server; HttpSessionState Session;
------解决方案--------------------------------------------------------
Session换成context.Session试试
------解决方案--------------------------------------------------------
session回丢的。。。所以你最好结合cooki
------解决方案--------------------------------------------------------
首页在ashx页面中使用session需要用context。Session 还有看是否引用了system.web.sessionstate这个空间,不然你继承了那个接口也是没用的