自定义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>