<authentication mode="Forms">
      <forms 
        name=".ASPXAUTH"
        loginUrl="default.aspx"
        defaultUrl="Download/Download.aspx">
        <credentials passwordFormat="Clear">
          <user name="test" password="test"/>
        </credentials>
      </forms>
    </authentication>
    <authorization>
      <allow users="*"/>
    </authorization>当在这个配置下,我的身份是什么呢,如何查看呢?还有我想实现部分页面可以不身份验证,而有些页面必须身份验证,我该如何配置呢?

解决方案 »

  1.   

    FormsIdentity identity = User.Identity as FormsIdentity;
                FormsAuthenticationTicket ticket = identity.Ticket;
                Response.Write(string.Format("用户名:{0}<br/>", identity.Name));
                Response.Write(string.Format("请求时间:{0}<br/>", ticket.IssueDate));
                Response.Write(string.Format("过期时间:{0}<br/>", ticket.Expiration));
                Response.Write(string.Format("是否持久:{0}<br/>", ticket.IsPersistent));我想在没有验证的时候也获得此次访问网站的用户名?
      

  2.   

    Forms验证
       //创建身份验证票据
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
             UserName.Text, DateTime.Now, DateTime.Now.AddSeconds(40), false, roles);
            string encryptedTicket = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName);
            cookie.Value = encryptedTicket;
            Response.Cookies.Add(cookie);
            Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text,false),true);
    参考
    参考