📄 logon.aspx.cs
字号:
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;
using System.Reflection;
public partial class Logon : System.Web.UI.Page,ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
//从cookie中获取身份验证票信息
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (authCookie == null)
{
ImageButton1.Attributes.Add("onclick", "logon();return false;");
ImageButton3.Attributes.Add("onclick", "login();return false;");
}
else
{
Response.Redirect("userfavor.aspx");
}
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("Register.aspx");
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
}
public string result;
public string GetCallbackResult()
{
//为便于查看加载效果,添加延时
System.Threading.Thread.Sleep(1000);
string[] parts = result.Split('|');
//搜索名为MethodName的方法
MethodInfo method = this.GetType().GetMethod(parts[0]);
//定义一个object数组用来保存参数
object[] args = new object[parts.Length - 1];
Array.Copy(parts, 1, args, 0, args.Length);
return (string)method.Invoke(this, args);
}
public void RaiseCallbackEvent(string eventArgument)
{
result = eventArgument;
}
public string confirm(string name,string psw)
{
DataVisit mydv = new DataVisit();
bool n= mydv.Confirm(name,psw);
if (n == true)
{
string UserRoles = mydv.GetRoles(name);//获取用户角色的字符串
//建立身份验证票据对象
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, DateTime.Now.AddHours(1), false, UserRoles, "/");
if (RadioButton4.Checked)
Ticket.Expiration.AddHours(2);
if (RadioButton2.Checked)
Ticket.Expiration.AddDays(1);
if (RadioButton1.Checked)
Ticket.Expiration.AddMonths(1);
if (RadioButton3.Checked)
Ticket.Expiration.AddYears(1);
//加密序列化验证票为字符串
string HashTicket = FormsAuthentication.Encrypt(Ticket);
//创建cookie
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
//输出cookie
Context.Response.Cookies.Add(UserCookie);
return "登录成功!";
}
else
return "用户名或密码错误?";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -