緩衝引起的session問題(ajax,js,jquery,asp.net,C#)

來源:互聯網
上載者:User

AsyncData.ashx檔案

public void ProcessRequest (HttpContext context) {
        string action = context.Request.QueryString["action"];//getcity,getstore
        string arg = context.Request.QueryString["arg"];// areaGUID,
        string pwd = context.Request.QueryString["pwd"];//user login password
        StringBuilder strResult = new StringBuilder();
       
        if (action == "userLogin")
        {
            Model.BJ_UserInfo userModel = new Model.BJ_UserInfo();
            BLL.BJ_User userBll = new BLL.BJ_User();
            UserInfo ui = new UserInfo();
           
            if (string.IsNullOrEmpty(arg) || string.IsNullOrEmpty(pwd))
                return;
            else
                userModel = userBll.GetModel(arg, WebUtility.GetMD5(pwd));
            if (userModel != null)
            {
                ui.UserGUID = userModel.UserGUID.ToString();
                ui.UserName = userModel.UserName;
                ui.RealName = userModel.RealName;
                ui.SecurityGUID = userModel.SecurityGUID.ToString();
                //ui.IP = WebUtility.GetIpAddress;
                //ui.StoreName = IpLocation(ui.IP);
                context.Session["userinfo"] = ui;
                strResult.Append(ui.UserName);
            }
            else
                strResult.AppendFormat("0");
        }
       }

 

CheckLogin.js檔案

//---------------------javascript-------------------------------
jQuery(function($){
   
    $("#btnLogin").click(function(){        
        var target1 = $("#txtUserName");
        var target2 = $("#txtPwd");   
        if(target1.val()=='')
        {
            alert('使用者名稱不可為空!');
            return;
        }
        if(target2.val()=='')
        {
            alert('密碼不可為空!');
            return;
        }
        else
           
            funAjaxText("userLogin", target1.val(), target2.val());           
    });
   
    var funAjaxText = function(action, username,pwd){
        $.ajax({
            type: "GET",
            url: "../Controls/AsyncData.ashx?action="+ action +"&arg="+username+"&pwd="+pwd,
            beforeSend: function(data){
            },
            success: function(data){            
                    if(data=="0")
                    {
                        $("#txtPwd").val("");
                        alert("使用者名稱或密碼有誤!");                       
                    }
                    else
                    {                       
                        window.location.href="MyBJ/MyBJ.aspx";
                    }                               
                }           
        });
    };   
});

首頁使用者登入,進行退出時,清空當前會話

Session.Clear();
        Session.Abandon();
        Response.Redirect("index.aspx");

並跳轉到前頁(重新整理),

再次登入時,登入成功,跳轉到mybj.aspx頁面

page_load()

{

UserInfo userModel = new UserInfo();
        userModel = (UserInfo)Session["userinfo"];
        if (userModel == null)
        {
            WebUtility.ShowMessageAndRedirect("你還沒有登入!","../index.aspx", this.Page);           
        }

}

會出現,session["userinfo"]為空白的情況。

這裡的問題是緩衝,

解決方案是在進行非同步資料請求時,加多一個隨機數,以使此請求不同於前,於是才不會去讀取緩衝。

url: "../Controls/AsyncData.ashx?action="+ action +"&arg="+username+"&pwd="+pwd+"&update="+Math.random(),

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.