在asp.net中没有获取主页加载中的会话值

时间:2014-09-09 10:32:52

标签: c# javascript jquery asp.net session

我正在使用c#在asp.net中开发一个应用程序。在我的应用程序中,一些页面是简单的html,其中一些是与主页面关联的aspx。在html页面中,我通过ajax调用设置会话,同时我通过相同的进程获取当前会话。设置会话和获取html页面之间的会话工作正常。但是当一个html页面重定向到aspx页面然后主页面没有得到会话。如何将会话从html传递到aspx母版页。请帮忙。

网络方法代码:

[WebMethod(EnableSession=true)]
public string getUserID()
{
    try
    {
        if (Session["User_ID"] != null)
        {
            uid = Convert.ToString(Session["User_ID"]);
            if (uid.Contains("temp@"))
            {
                return "NA";
            }
            else
            {
                return uid;
            }
        }
        else
        {
            return "NA";
        }
    }
    catch (NullReferenceException)
    {
        return "NA";
    }
}

[WebMethod(EnableSession=true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ValidateCustomer(string cust_email, string cust_passkeys, string temp_userid)
{
    sql_query = "select Password_Hash from Customer_Master where Customer_Email='" + cust_email + "'";
    result_ds = new DataSet();
    result_ds = DBAccess.selectQuery(sql_query);
    bool pwdStatus;

    if (result_ds.Tables[0].Rows.Count > 0)
    {
        string pwdHash = Convert.ToString(result_ds.Tables[0].Rows[0][0]);
        pwdStatus = PasswordHash.PasswordHash.ValidatePassword(cust_passkeys.Trim(), pwdHash);

        if (pwdStatus)
        {
            sql_query = "update Temporary_Shopping_Cart set Customer_ID='" + cust_email.Trim() + "' where Customer_ID='" + temp_userid.Trim() + "'";
            status = DBAccess.executeQuery(sql_query);

            Session["User_ID"] = cust_email.ToString();
            return "TRUE";
        }
        else
            return "FALSE";
    }
    else
    {
        return "FALSE";
    }

}

JQuery代码:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "Services/Utils_General.asmx/getUserID",
    data: "{}",
    dataType: "JSON",
    async: false,
    cache: false,
    success: function (data) {
        var uid = data.d.toString();
        alert(uid);
        if (uid != "NA") {
            document.getElementById("loginPanel").innerHTML = "<a href='#' id='dropdownMenu1' data-toggle='dropdown'>" + uid + "</a><ul class='dropdown-menu' role='menu' aria-labelledby='dropdownMenu1'><li role='presentation'><a role='menuitem' tabindex='-1' href='my-profile.aspx'>My Profile</a></li><li role='presentation'><a role='menuitem' tabindex='-1' href='shipping-billing.aspx'>Shipping & Billing Info</a></li><li role='presentation'><a role='menuitem' tabindex='-1' href='#'>Order History</a></li><li role='presentation'><a role='menuitem' tabindex='-1' href='#'>Change Password</a></li><li role='presentation'><a href='#Logout' id='btnLogout'>Logout</a></li></ul>";
        }
        else {
            document.getElementById("loginPanel").innerHTML = "<a href='#' data-toggle='dropdown' class='dropdown-toggle'>Login</a><ul class='dropdown-menu top-login-form'><li id='loginAlertArea'></li><li><form action='#'><div class='form-group'><input id='txtLoginUserID' type='text' placeholder='Login ID' class='form-control' /><div id='validator_txtLoginUserID'></div></div><div class='form-group'><input id='txtLoginPassword' type='password' placeholder='Password' class='form-control' /><div id='validator_txtLoginPassword'></div></div><div class='form-group'><input type='button' class='btn btn-success' id='btnLogin' data-loading-text='Signing In...' value='Login' /><button type='button' class='btn btn-link pull-right'>Forgot Password?</button></div><div class='form-group text-center'><button type='button' class='btn btn-link member'><span class='glyphicon glyphicon-user'></span> Become a member!</button></div></form></li></ul>";
        }
    },
    error: function (result, d, s) {
        alert(s);
    }
});

母版页参考:

<script src="js/App_JS/LoginStore.js" type="text/javascript"></script>

JQuery引用已添加到母版页中,但它没有给出预期的结果。 请帮忙。

0 个答案:

没有答案