_登陆验证的问题,我在登陆页面输入用户名和密码后登陆Default.aspx,
然后我在注销退出,当我试验着用输入网地址的方法后竟然还可以登陆,登陆后虽然其他操作都不可以了,如果刷新一次就不能登陆,但是我希望注销后是绝对不能进入,我的代码有什么问题请指教!
_________________________________________________
Web.Config<?xml version="1.0"?>
<!-- 
    注意: 除了手动编辑此文件以外,您还可以使用 
    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
     “网站”->“Asp.Net 配置”选项。
    设置和注释的完整列表在 
    machine.config.comments 中,该文件通常位于 
    \Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!-- 
            设置 compilation debug="true" 将调试符号插入
            已编译的页面中。但由于这会 
            影响性能,因此只在开发过程中将此值 
            设置为 true。
        -->
<compilation debug="true"/>
<!--
            通过 <authentication> 节可以配置 ASP.NET 使用的 
            安全身份验证模式,
            以标识传入的用户。 
        -->
    <authentication mode="Forms">
      <forms loginUrl="landing.aspx"  defaultUrl="Default.aspx"  name=".ASPXAUTH" >
      </forms>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
</system.web>
</configuration>
_________________________________________________________________________
landing.aspx   protected SqlConnection createLoginConn()
    {
        SqlConnection cn = new SqlConnection("server=.;database=Login;uid=sa;pwd=xxx");
        return cn;
    }
    
            
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        string UserName = this.TextBox1.Text;
        string Password = this.TextBox2.Text;
        SqlConnection cn = createLoginConn();
        cn.Open();
        SqlCommand cmd = new SqlCommand
            ("select count(*) from tb_login where Name=@Name and Pass=@Pass ", cn);
        cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = UserName;
        //MD5加密
        cmd.Parameters.Add("@Pass", SqlDbType.VarChar, 50).Value =
            FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "MD5");
        int i = (int)cmd.ExecuteScalar();
        if (i > 0)
        {
            //添加登陆日志
            //Response.Write("登陆成功!");
             cmd = new SqlCommand("insert EntryLog values('" + TextBox1.Text + "','" + DateTime.Now.ToString() + "')",cn);
            cmd.ExecuteNonQuery();
            cn.Close();
          Session["name"] = this.TextBox1.Text;
            FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
            Response.Redirect("Default.aspx");        }
        else
        {
            Response.Write("登陆失败!");        }    }
___________________________________________________________________________________
 Default.aspxprotected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["name"] != null)
            {
                //查询数据....略>
                    
            }
            else
            {
                Response.Redirect("landing.aspx");
            }
        }
        else 
        {
            Response.Redirect("landing.aspx");
        }
        Session.Clear();    }     //注销用户
  protected void Button2_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("landing.aspx");
    }
}
____________________________________________________________________

解决方案 »

  1.   

    额 这个问题是不是你的浏览器的cookies的问题啊
      

  2.   

    估计是浏览器的缓存。试试看在Page_Load里+ Response.Buffer = true;
       Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
       Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
       Response.Expires = 0;
       Response.CacheControl = "no-cache";
       Response.Cache.SetNoStore();
      

  3.   

    Default.aspx protected void Page_Load(object sender, EventArgs e) 
        { 
              if (Session["name"] != null) 
                { 
                } 
                else 
                { 
                    Response.Redirect("landing.aspx"); 
                }         if (!IsPostBack) 
            { 
                   //查询数据....略> 
                        
             } 
            else 
            { 
                Response.Redirect("landing.aspx"); 
            } 
            Session.Clear();     }     //注销用户 
      protected void Button2_Click(object sender, EventArgs e) 
        { 
            FormsAuthentication.SignOut(); 
            Response.Redirect("landing.aspx"); 
        }