62,263
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
string username = TextBox1.Text;//读取用户名
string password = TextBox2.Text;//读取密码
if (username == "wbf" && password == "123456")//模拟数据库验证 假设用户登录成功
{
string userRoles = "1";//用户组,假设用户组ID为1
string userId = "30";//用户ID假设为30
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddDays(6), false, userId+","+userRoles, "/");
string hashTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket);
Response.Cookies.Add(cookie);
if (Request["ReturnUrl"] != null)
{
Response.Redirect(Request["ReturnUrl"]);
}
}
}
<authentication mode="Forms">
<forms name=".login" protection="All" loginUrl="Login.aspx" timeout="30" path="/">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>