现在的位置: 首页 > 综合 > 正文

有些东西老是用到,老是东找西找,把它放在这里做个记号自己好找

2013年02月05日 ⁄ 综合 ⁄ 共 1156字 ⁄ 字号 评论关闭

自定义Ticket验证代码:

string username=TextBox1.Text;
   string password=TextBox2.Text;
   bool   isPersistent = CheckBox1.Checked;
   string userData="Leisang";

   FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
    1,
    username,
    System.DateTime.Now,
    System.DateTime.Now.AddMinutes(30),
    isPersistent,
    userData,
    FormsAuthentication.FormsCookiePath);
   string encTicket = FormsAuthentication.Encrypt(ticket);
   Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
   Response.Redirect(FormsAuthentication.GetRedirectUrl(username,isPersistent));

读取自定义Ticket
string cok=Request.Cookies[".Leisang"].Value.ToString();
   FormsAuthenticationTicket ticket=FormsAuthentication.Decrypt(cok);
   Label1.Text=ticket.Name+ticket.UserData.ToString();

部分验证WebConfig 1
<authentication mode="Forms">
 <forms name=".TACenter" loginUrl="login.aspx" protection="All" timeout="60" path="/"/>
    </authentication>
    <authorization>
        <deny users="?"/>
    </authorization>

部分验证WebConfig 2
。。。
 </system.web>
   <location path="RegCenter/reg.aspx">
  <system.web>
   <authorization>
   <allow users="?"/>
   </authorization>
  </system.web>
 </location>
</configuration>

抱歉!评论已关闭.