身份验证代码如下
webform1:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
FormsAuthentication.SignOut();
}
if(HttpContext.Current.Request.Cookies["aaa"]!=null)
{
HttpContext.Current.Request.Cookies.Remove("aaa");
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
cookie=new HttpCookie("aaa");
cookie.Values["name"]="zou";
HttpContext.Current.Request.Cookies.Add(cookie);
Response.Redirect("WebForm2.aspx");
}
webform2:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Page.User.Identity.IsAuthenticated==false)
Server.Transfer("WebForm1.aspx");
}调试的结果是Page.User.Identity.IsAuthenticated一直都是等于false,我实在不知道问题出在哪里,懂的朋友来帮帮忙。

解决方案 »

  1.   

    Private Function CreateAuthTicket(ByVal userName As String, ByVal roles As String, _
            ByVal persistent As Boolean) As FormsAuthenticationTicket
            Return New FormsAuthenticationTicket(1, userName, DateTime.Now, _
                DateTime.Now.AddMinutes(60), persistent, roles)
        End Function    Private Function CreateAuthCookie(ByVal authTicket As FormsAuthenticationTicket) As HttpCookie
            Return New HttpCookie(FormsAuthentication.FormsCookieName, _
                FormsAuthentication.Encrypt(authTicket))
        End Function
    登陆完成:
     Dim authTicket As FormsAuthenticationTicket     
     Dim authCookie As HttpCookie                  authTicket = CreateAuthTicket(txtUserID.Text, CStr(viewstate("roles")), False)
                            authCookie = CreateAuthCookie(authTicket)
                           HttpContext.Current.Response.Cookies.Add(authCookie)                        If Request("ReturnUrl") Is Nothing Then
                    Response.Redirect("./Menu/Menu.aspx")
                Else
                    Response.Redirect(Request("ReturnUrl"))
                End If
      

  2.   

    赫赫,不用这么麻烦,简单点:
    if(验证通过)
    {
    System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username,CheckBox1.Checked);}
    即可
      

  3.   

    leisang(我自飘零) 
    如果是第一次登陆呢?这样的代码不行呀
      

  4.   

    HttpContext.Current.User.Identity.IsAuthenticated
    我想知道怎么才能让IsAuthenticated得到的值是true也就是验证通过的用户。
      

  5.   

    你的验证方式是Forms吧,当是你的验证代码中并未为合法登陆的用户创建一个身份凭据,需要用如下代码为用户创建一个凭据,
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket("aaa", false, 60);
    Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, ticket));
      

  6.   

    drone(雄蜂) 
    能写的完整点吗?谢谢