我使用FORMS表单验证,登录页面有两个选择(1.无  2.1年),选择1就使用session,选择2就使用cookies可是我选择1并登录成功后,不能进入该页面我的CONFIG配置如下:
<authentication mode="Forms"> 
 <forms name="MyAppFormsAuth" loginUrl="Afreshtwo.aspx" protection="Encryption" timeout="20" path="/">
 </forms>
</authentication>代码如下:
if(Session["id"].ToString() != "" || User.Identity.Name!=null)
{}
else
{}

解决方案 »

  1.   

    选择2使用cookies的时候就可以登录
      

  2.   

    if(r.Read())
    {
    r.Close();
    FormsAuthenticationTicket ticket = null;
    if(this.dlValidity.SelectedItem.Value == "0")
    {
    Page.Session["id"]=1;
    Session.Timeout = 30;
    string strRedirect = @"Privatelyowned/SuccedInto.aspx";
    Response.Redirect(strRedirect,true);
    }
    else
    {
    ticket = new FormsAuthenticationTicket(1,this.tbUser.Text,DateTime.Now,
    DateTime.Now.AddDays(double.Parse(this.dlValidity.SelectedItem.Value)),true,"User");

    string cookieStr =  FormsAuthentication.Encrypt(ticket);

    HttpCookie cookie =new HttpCookie(FormsAuthentication.FormsCookieName,cookieStr);
    cookie.Expires=ticket.Expiration;
    cookie.Path = FormsAuthentication.FormsCookiePath;
    Response.Cookies.Add(cookie);
    string strRedirect = @"Privatelyowned/SuccedInto.aspx";
    Response.Redirect(strRedirect,true);
    }
    }
      

  3.   

    if(r.Read())
    {
    r.Close();
    FormsAuthenticationTicket ticket = null;
    if(this.dlValidity.SelectedItem.Value == "0")
    {
    Page.Session["id"]=1;
    Session.Timeout = 30;
    string strRedirect = @"Privatelyowned/SuccedInto.aspx";
    Response.Redirect(strRedirect,true);
    }
    else
    {
    ticket = new FormsAuthenticationTicket(1,this.tbUser.Text,DateTime.Now,
    DateTime.Now.AddDays(double.Parse(this.dlValidity.SelectedItem.Value)),true,"User");


    string cookieStr =  FormsAuthentication.Encrypt(ticket);

    HttpCookie cookie =new HttpCookie(FormsAuthentication.FormsCookieName,cookieStr);
    cookie.Expires=ticket.Expiration;

    cookie.Path = FormsAuthentication.FormsCookiePath;
    Response.Cookies.Add(cookie);
    string strRedirect = @"Privatelyowned/SuccedInto.aspx";
    Response.Redirect(strRedirect,true);
    }
    }
      

  4.   

    只知道forms表单认证就是和cookie挂钩的。你用FormsAuthenticationTicket没有cookie行吗
      

  5.   

    如果用session登录,那下面这句
    if(Session["id"].ToString() != "" || User.Identity.Name!=null)
    User.Identity.Name就会=null,那就相当于未登录了
    代码逻辑有问题
      

  6.   

    if(Session["id"].ToString() != "" || User.Identity.Name!=null)的意思是只要有一个成立就执行后面的语句不执行else虽然User.Identity.Name!=null不成立但是还是可是执行下面的语句
      

  7.   

    User.Identity.Name!=null改成Request.IsAuthenticated试试
      

  8.   

    Session["id"].ToString() != "" 
    改为
    Session["id"] != null
      

  9.   

    还是一样 就是因为Session["id"] != null不行才改成
    Session["id"].ToString() != "" 的