2 u012742287 u012742287 于 2013.11.06 14:41 提问

.net web项目,首页ajax请求session为空,其他页面可以获取到,急。。。。。。

JS代码:、、、、

var str="http://"+location.hostname+"/";
var params = str+ '/brandlist.aspx?Option=GetLoginInfo&t=' + new Date();
alert(params)
jQuery.ajax({
type: "get",
url: params,
dataType :'text',
success: function(msg){
var str = msg.split('|');
document.getElementById('head_reg').href = str[1];
document.getElementById('head_login').href = str[2];
if (str[0] == '') {
document.getElementById('head_reg').innerText = '[免费注册]';
document.getElementById('head_login').innerText = '[请登录]';
} else {
document.getElementById('head_reg').innerText = '['+str[0]+']';
document.getElementById('head_login').innerText = '[退出]';
}
try {
document.getElementById('head_cartItemCount').innerText = str[3];
} catch (e) {}

}
});

C#代码。。。。。

            public partial class brandlist : System.Web.UI.Page, IHttpHandler, IRequiresSessionState
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strOption = eShop.WebPage.PageRequest.GetQueryString("Option");
            if (strOption == "GetLoginInfo")
            {
                eShop.Web.ProfileCommon profile = new eShop.Web.ProfileCommon();

                string[] loginInfo = new string[4];
                if (Session["MemberID"] == null)
                {//需登录与注册

                    loginInfo[0] = string.Empty;
                    loginInfo[1] = eShop.TemplateAction.Common.UrlStr("registered", "", "membercenter/");   //注册
                    loginInfo[2] = eShop.TemplateAction.Common.UrlStr("login", "", "membercenter/");    //登录
                    loginInfo[3] = profile.ShoppingCart.CartItems.Count.ToString(); //购物车数量
                }
                else
                {//需‘我的帐户’和退出
                    loginInfo[0] = Session["MemberID"].ToString();
                    loginInfo[1] = eShop.TemplateAction.Common.UrlStr("member_index", "", "membercenter/"); //我的帐户
                    loginInfo[2] = eShop.TemplateAction.Common.UrlStr("exitmembercenter", "", "membercenter/");    //退出
                    loginInfo[3] = profile.ShoppingCart.CartItems.Count.ToString();
                }

                Response.Write(string.Join("|", loginInfo));
                Response.End();
            }
            Response.Write(eShop.TemplateAction.Common.eShop_PageContent("brandlist"));
        }
    }
}

只有主页获取不到,其余页面都有值,可以确定session中一定有值

1个回答

liuxingyuname
liuxingyuname   2013.11.06 17:22

您檢查下是否主頁加載後是否Session["X"]是否已經有值啊?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!