求表单验证票的使用方法?
求表单验证票的使用方法?
立即节帖
[解决办法]
这是我以前用了,你看看.
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class login : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string us = Users.Text; string ps = Password.Text; if (checkusers(us, ps)) { //FormsAuthentication.RedirectFromLoginPage(us,false); FormsAuthenticationTicket myTicket = new FormsAuthenticationTicket( 1, us, System.DateTime.Now, System.DateTime.Now.AddDays(30), false, "admin", "/"); string myEncrypt = FormsAuthentication.Encrypt(myTicket); HttpCookie myHttpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, myEncrypt); this.Response.Cookies.Add(myHttpCookie); if (HttpContext.Current.Request["ReturnUrl"] == null) { this.Response.Redirect("default.aspx"); } else { this.Response.Redirect(HttpContext.Current.Request["ReturnUrl"].ToString()); } } } bool checkusers(string users, string password) { return true; }}using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string name = getTicket().Name; this.Response.Write(name); } FormsAuthenticationTicket getTicket() { string FormsCookieName = FormsAuthentication.FormsCookieName; HttpCookie myHttpCookie = HttpContext.Current.Request.Cookies[FormsCookieName]; if (myHttpCookie == null) { return null; } else { return FormsAuthentication.Decrypt(myHttpCookie.Value); } }}