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) { Title = "تسجيل الدخول "; if (User.Identity.IsAuthenticated && Request.QueryString["ReturnUrl"] != null) { Response.Redirect("NotAuthorized.aspx"); } lblMessage.Text = ""; } protected void btnLogin_Click(object sender, EventArgs e) { User _user = new User(); DBOperations dbo = new DBOperations(); _user = dbo.CheckUser(txtUserid.Text); if (_user != null) { if (_user.Password == txtPassword.Text) { if (dbo.GetcheckActive(txtUserid.Text) == true) { FormsAuthenticationTicket Authticket = new FormsAuthenticationTicket( 1, txtUserid.Text, DateTime.Now, DateTime.Now.AddMinutes(30), chkRemeberMe.Checked, _user.Role, FormsAuthentication.FormsCookiePath); string hash = FormsAuthentication.Encrypt(Authticket); HttpCookie Authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); if (Authticket.IsPersistent) Authcookie.Expires = Authticket.Expiration; Response.Cookies.Add(Authcookie); string returnUrl = Request.QueryString["ReturnUrl"]; returnUrl = _user.Role.ToString(); if (returnUrl == null) returnUrl = "/"; Response.Redirect(returnUrl); returnUrl = ""; } else lblMessage.Text = "انتظر تفعيل الادراة"; } else { lblMessage.Text = "كلمة المرور خاطئة"; } } else { lblMessage.Text = "الاسم غير مسجل "; } } }