第一次登录,没有问题,退出后再登陆点击其他页面出现Session失效问题;如果关闭浏览器,重新登录也没有问题是用ajax做的登陆,代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class ajax : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {        if (Request["id"] != null)
        {
            Session["userid"] = null;
            Response.Redirect("index.aspx");
        }        if (Request["pwd"] != null && Request["user"] != null)
        {
            xiang.BLL.UserInfo userInfo = new xiang.BLL.UserInfo();
            if (uInfo.Exists(Request["user"]))
            {
                xiang.Model.UInfo model_useInfo = new xiang.Model.UserInfo();
                model_uInfo = userInfo.GetModel(Request["userS"]);
                if (model_uInfo.password == Request["pwdS"])
                {
                    if (model_uInfo.state.Value.ToString() == xiang.BLL.UInfoState.ZhuXiao)
                    {
                        Response.Clear();
                        Response.Write("false");
                        Response.End();
                        return;
                    }
                    Session["userid"] = model_useInfo.userid.ToString();
                    model_uInfo = uInfo.GetModel(Request["user"]);                    model_uInfo.loginip = Request.UserHostAddress;
                    uInfo.Update(model_useInfo);                    Response.Clear();
                    Response.Write("<div style=\"font:bold 13px 宋体;padding-left:5px;line-height:20px;color:#000000;background-color:#EFF6FE;height:20px; border:0 0 1px 0;\">欢迎您来到好范文网!</div>");
                    Response.Write("<div style=\"font:13px 宋体;margin-top:5px;text-align:center;\">您目前可阅读文章数:" + model_useInfo.candownloadnumber.ToString() + "篇</div>");
                    Response.Write("<div style=\"font:13px 宋体;margin-top:5px;text-align:center;\">您目前可下载文章数:"+model_useInfo.canreadnumber.ToString()+"篇</div>");
                    Response.Write("<div style=\"font:13px 宋体;margin-top:5px;text-align:center;\"><a href=\"/ArticalAdd.aspx\" target=\"_blank\">立即上传1篇换取6-20篇文档</a></div>");
                    Response.Write("<div style=\"font:13px 宋体;margin-top:5px;text-align:center;\"><span><a href=\"UserInfo.aspx\">我的中心</a> </span><span style=\"padding-left:5px;\"><a href=\"ArticalManage.aspx\">文档管理</a></span><span style=\"padding-left:10px;\">退出</span></div>");
                    Response.End();
                }
                else
                {
                    Response.Clear();
                    Response.Write("false");
                    Response.End();
                }
            }
            else
            {
                Response.Clear();
                Response.Write("false");
                Response.End();
            }
        }
    }
}

解决方案 »

  1.   

    退出时sesion是否清除,那就要判断session是否为null
    BasePage
    保存session可使用StateServer
      

  2.   


     已经改成StateServer这个模式也是这样,真的郁闷了
      

  3.   

    那你用HttpWatch看下,访问别的页面,cookie里是不是没有aspsessionid这项
      

  4.   

    如果没有,你用ajax登录的话,就应该返回下sessionid,然后把sessionid写进cookie当中,不知道这样可不可以,我也没试过。