http://code365.com/tech/1/15/Article/2379.Asp你自己看看吧

解决方案 »

  1.   

    有没有修改Global.asax或者是web.config中的sessionstate timeout时间
      

  2.   

    还有你可以跟踪一下你的Session,把他Response.Write()出来,看看是什么时候丢失的
      

  3.   

    你是怎么重定向的?是Response.Redirect("a.aspx");还是Response.Redirect("http://www.csdn.net/a.aspx")
      

  4.   

    web.config以及bin目录下文件的修改都会导致web应用重启,另外防病毒软件对这些文件的扫描也会导致这个问题,而应用重启后,session肯定会丢失。
      

  5.   

    我的目录:
    root
    {
    主要的界面都在这里
    Default.aspx等等..
    Controls{控件存放地,登录控件,页头,页尾等}
    Process{Session控制处,可以存储,获得指定的Session}
    }//这里是登录控件处,查看是否验证用户,验证的话就显示用户名if(Request.IsAuthenticated!=true)
    {
    SpanLogin.Visible = true;
    SpanLogOut.Visible = false;
    }
    else
    {
    SpanLogin.Visible = false;
    SpanLogOut.Visible = true;
    Process.AccountController accountController = new Process.AccountController();
    AccountInfo myAccount = accountController.GetAccountInfo(false);
    this.LabelUserName.Text = myAccount.UserName.Trim();
    }
    //Session控制登录处
    public bool ProcessLogin(string userName, string password)
    {
    Account account = new Account();
    AccountInfo myAccountInfo = account.SignIn(userName, password);
    if (myAccountInfo != null) 
    {
    HttpContext.Current.Session[ACCOUNT_KEY] = myAccountInfo;
        return true;//这里确实有Session了
    }
    return false;

    //获得保存在Session里的用户信息,这里就没用了
    public AccountInfo GetAccountInfo(bool required)
    {
    AccountInfo myAccount = (AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY];
    return myAccount;//返回为null
      

  6.   

    具体你可以查看一下petshop的源代码,看看是怎么来管理session的。
      

  7.   

    我的操作过程是这样的
    进入主页面后,通过菜单进入Login.aspx页面,在那里登录,成功后在该页面的显示用户信息就不正常。Session已经重起了。
      

  8.   

    项目重新生成,session也会丢!
      

  9.   

    这是我在登录界面作的测试;我登录成功后就来获得该Session值,可是获得的是null
    private void BtnLogin_Click(object sender, System.EventArgs e)
    {
    this.LabelErrorMsg.Visible=false;
    if (Page.IsValid) 
    {

    // Get the user info from the text boxes
    string username = this.txtUserName.Text;
    string password = this.txtUserPassword.Text; // Hand off to the account controller to control the naviagtion
    Process.AccountController accountController = new Process.AccountController(); if (!accountController.ProcessLogin(username, password))
    { // If we fail to login let the user know
    LabelErrorMsg.Text = "登录失败!请重新登录!";
    LabelErrorMsg.Visible = true;
    }
    }
    } private void BtnRegistUser_Click(object sender, System.EventArgs e)
    {
    Process.AccountController accountController = new Process.AccountController(); // Retrieve the account information from the account controller
    AccountInfo myAccount = accountController.GetAccountInfo(false);//这里返回的就是null值 LabelErrorMsg.Text = myAccount.UserName;
    LabelErrorMsg.Visible=true;
    }
      

  10.   

    重定向我是通过<a herf=""/>来进行的呀,这不会出毛病吧
      

  11.   

    试试:
    1.启动服务: ASP.NET State Service
    2.设置Web.Config:
     <sessionState mode="StateServer" ....
      

  12.   

    To: qiuji(忆秋季) 
    那个方法我试过了,不行的!
      

  13.   

    我想是你的程序跨越了多个Web应用程序吧。因为我按照你说的按照PetShop的模式做了个试验,但没用Session丢失的现象。不信你可以自己在重做个试验看看。如果你还不懂的话可以看看我给你的网页,那里的解释蛮详细的。