前台JS获取ASHXvar intervalID = 0;
                intervalID = window.setInterval(function () {
                    $.ajax({
                        type: "POST",
                        datatype: "text",
                        url: "../Ajax/HandlerGetUploadProgress.ashx",
                        async: false,
                        cache: false,
                        data: { },
                        beforeSend: function () {
                        },
                        success: function (result) {
                            if (result != "null" && result == 100) {
                                clearInterval(intervalID);
                                $("#<%=lblShowProgress.ClientID %>").html("").hide();
                            }
                            else if (result != "null") {
                                $("#<%=lblShowProgress.ClientID %>").html(result + "%").show();
                            }
                            else {
                                $("#<%=lblShowProgress.ClientID %>").html("").show();
                            }
                        },
                        error: function (result, status) {
                        }
                    });
                }, 500);ashx文件中if (context.Session != null && context.Session["ShopCurrentPercentage"] != null && context.Session["ShopTotalPercentage"] != null)
            {
                int currentpercentage = Convert.ToInt32(context.Session["ShopCurrentPercentage"]);
                int totalpercentage = Convert.ToInt32(context.Session["ShopTotalPercentage"]);
                context.Response.ContentType = "text/plain";
                context.Response.Write(Math.Ceiling((double)currentpercentage * 100 / totalpercentage));
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write(DateTime.Now.ToString("yyyyMMddhhmmss"));
            }

解决方案 »

  1.   

    据我所知,你是取不到session的值的,session在当前线程未结束前所有的操作其他UI现场看不到的
      

  2.   

    你可以用application做基于hash的键值对代替
      

  3.   

    那是否意味着不能使用session来实现模拟上传文件进度条.C#后台文件需要做一部分的处理,并且会及时更新进度数据。
      

  4.   

    IRequiresSessionState 这个会阻塞其它Session请求.....我这边就碰到了打开aspx页面,该页面堵塞了,然后定时轮询的继承自IReadOnlySessionState的ashx请求也被阻塞了
      

  5.   

    fileupload上传显示进度 
      

  6.   

    楼上的要么实验不了,要么另外配置了session state server.
      

  7.   

    <%@ WebHandler Language="C#" Class="VerificationHandler" %>using System;
    using System.Web;
    using System.Web.SessionState;public class VerificationHandler : IHttpHandler, IRequiresSessionState
    {
        
        public void ProcessRequest (HttpContext context) {
            string Verification = context.Request["Verification"].ToLower();
            if (Verification != context.Session["validate_code"].ToString().ToLower())  //判断用户填写的验证码和生成的验证码是否一致,当不一致时触发的事件
            {
                context.Response.Write("false");
            }
            else
            {
                context.Response.Write("true");
            }
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}
    楼主请给分
      

  8.   

    引用using System.Web.SessionState; HttpContext.Current.Session[""]