温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Asp.net2.0的电影在线点播系统片段源码
当前文件:
MovieShowSample/Logon.aspx.cs,打开代码结构图
MovieShowSample/Logon.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Reflection; 12
public partial class Logon : System.Web.UI.Page,ICallbackEventHandler 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
//从cookie中获取身份验证票信息 17
string cookieName = FormsAuthentication.FormsCookieName; 18
HttpCookie authCookie = Context.Request.Cookies[cookieName]; 19
if (authCookie == null) 20
{ 21
ImageButton1.Attributes.Add("onclick", "logon();return false;"); 22
ImageButton3.Attributes.Add("onclick", "login();return false;"); 23
} 24
else 25
{ 26
Response.Redirect("userfavor.aspx"); 27
} 28
} 29
protected void ImageButton2_Click(object sender, ImageClickEventArgs e) 30
{ 31
Response.Redirect("Register.aspx"); 32
} 33
protected void RadioButton1_CheckedChanged(object sender, EventArgs e) 34
{ 35
36
} 37
public string result; 38
39
public string GetCallbackResult() 40
{ 41
//为便于查看加载效果,添加延时 42
System.Threading.Thread.Sleep(1000); 43
44
string[] parts = result.Split('|'); 45
//搜索名为MethodName的方法 46
MethodInfo method = this.GetType().GetMethod(parts[0]); 47
48
//定义一个object数组用来保存参数 49
object[] args = new object[parts.Length - 1]; 50
Array.Copy(parts, 1, args, 0, args.Length); 51
52
return (string)method.Invoke(this, args); 53
} 54
55
public void RaiseCallbackEvent(string eventArgument) 56
{ 57
result = eventArgument; 58
} 59
public string confirm(string name,string psw) 60
{ 61
DataVisit mydv = new DataVisit(); 62
bool n= mydv.Confirm(name,psw); 63
if (n == true) 64
{ 65
string UserRoles = mydv.GetRoles(name);//获取用户角色的字符串 66
//建立身份验证票据对象 67
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, DateTime.Now.AddHours(1), false, UserRoles, "/"); 68
69
if (RadioButton4.Checked) 70
Ticket.Expiration.AddHours(2); 71
if (RadioButton2.Checked) 72
Ticket.Expiration.AddDays(1); 73
if (RadioButton1.Checked) 74
Ticket.Expiration.AddMonths(1); 75
if (RadioButton3.Checked) 76
Ticket.Expiration.AddYears(1); 77
//加密序列化验证票为字符串 78
string HashTicket = FormsAuthentication.Encrypt(Ticket); 79
//创建cookie 80
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket); 81
//输出cookie 82
Context.Response.Cookies.Add(UserCookie); 83
84
return "登录成功!"; 85
86
} 87
else 88
return "用户名或密码错误?"; 89
} 90
91
} 92





}
}