Fartaj
سه شنبه 16 خرداد 1391, 19:10 عصر
سلام خدمت دوستان
من در ادامه یک پروژه سه لایه در قسمت login به مشکل خوردم جداول مربوط به login من به صورت زیر می باشد :
87917
و namespace های زیر رو به صفحه login اضافه کردم :
using System.Web.Security;
using System.Security.Principal;
و کد مربوط به دکمه login به صورت زیر می باشد :
bool result = Convert.ToBoolean(BLL.users.CheckUsernameAndPasswo rdMatch(txtusername.Text, txtpass.Text));
if (result)
{
string role = BLL.users.GetUserRoleByusername(txtusername.Text);
FormsAuthenticationTicket AuthTicket = new FormsAuthenticationTicket(1, txtusername.Text, DateTime.Now, DateTime.Now.AddHours(1), false, role);
string encryptedTicket = FormsAuthentication.Encrypt(AuthTicket);
HttpCookie AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(AuthCookie);
Response.Redirect(FormsAuthentication.GetRedirectU rl(txtusername.Text, chk_member.Checked));
}
else
{
lblmsg.Text = "نام کاربری یا رمز عبور اشتباه است ";
}
و کد global.asax :
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName.ToString()];
if (authCookie != null)
{
FormsAuthenticationTicket MyTicket;
MyTicket = FormsAuthentication.Decrypt(authCookie.Value);
FormsIdentity MyIdentity = new FormsIdentity(MyTicket);
GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyTicket.UserData.Split(new char[] { ',' }));
Context.User = MyPrincipal;
}
کد لایه DAL :
public string GetUserRoleByusername(string username)
{
return ExecuteScaler(System.Data.CommandType.StoredProced ure, "GetUserRoleByusername", new SqlParameter[] {
new SqlParameter("@username",username) }).ToString();
}
public string GetApproleByAppname(string applicationname)
{
return ExecuteScaler(System.Data.CommandType.StoredProced ure, "GetApproleByAppname", new SqlParameter[] {
new SqlParameter("@applicationname", applicationname)
}).ToString();
}
public bool CheckUsernameAndPasswordMatch(string username, string password)
{
return (bool) ExecuteScaler(System.Data.CommandType.StoredProced ure, "CheckUsernameAndPasswordMatch", new SqlParameter[] {
new SqlParameter("@username", username),
new SqlParameter("@password", password)
});
}
کد لایه BLL :
public int userid { get; set; }
public string username{ get; set; }
public string password { get; set; }
public string roles { get; set; }
public string email { get; set; }
public static string GetUserRoleByusername(string Username){
return users.GetUserRoleByusername(Username);
}
public static string GetApproleByAppname(string applicationname)
{
return users.GetApproleByAppname(applicationname);
}
public static string CheckUsernameAndPasswordMatch(string username,string password)
{
return users.CheckUsernameAndPasswordMatch(username,passw ord);
}
وقتی دکمه login رو می زنم کلا قفل می کنه
ممنون می شم اگه یک نگاهی به کدها بندازید جاییش اگر ایراد داشت بهم بگید ؟؟:گیج::گیج:
من در ادامه یک پروژه سه لایه در قسمت login به مشکل خوردم جداول مربوط به login من به صورت زیر می باشد :
87917
و namespace های زیر رو به صفحه login اضافه کردم :
using System.Web.Security;
using System.Security.Principal;
و کد مربوط به دکمه login به صورت زیر می باشد :
bool result = Convert.ToBoolean(BLL.users.CheckUsernameAndPasswo rdMatch(txtusername.Text, txtpass.Text));
if (result)
{
string role = BLL.users.GetUserRoleByusername(txtusername.Text);
FormsAuthenticationTicket AuthTicket = new FormsAuthenticationTicket(1, txtusername.Text, DateTime.Now, DateTime.Now.AddHours(1), false, role);
string encryptedTicket = FormsAuthentication.Encrypt(AuthTicket);
HttpCookie AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(AuthCookie);
Response.Redirect(FormsAuthentication.GetRedirectU rl(txtusername.Text, chk_member.Checked));
}
else
{
lblmsg.Text = "نام کاربری یا رمز عبور اشتباه است ";
}
و کد global.asax :
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName.ToString()];
if (authCookie != null)
{
FormsAuthenticationTicket MyTicket;
MyTicket = FormsAuthentication.Decrypt(authCookie.Value);
FormsIdentity MyIdentity = new FormsIdentity(MyTicket);
GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyTicket.UserData.Split(new char[] { ',' }));
Context.User = MyPrincipal;
}
کد لایه DAL :
public string GetUserRoleByusername(string username)
{
return ExecuteScaler(System.Data.CommandType.StoredProced ure, "GetUserRoleByusername", new SqlParameter[] {
new SqlParameter("@username",username) }).ToString();
}
public string GetApproleByAppname(string applicationname)
{
return ExecuteScaler(System.Data.CommandType.StoredProced ure, "GetApproleByAppname", new SqlParameter[] {
new SqlParameter("@applicationname", applicationname)
}).ToString();
}
public bool CheckUsernameAndPasswordMatch(string username, string password)
{
return (bool) ExecuteScaler(System.Data.CommandType.StoredProced ure, "CheckUsernameAndPasswordMatch", new SqlParameter[] {
new SqlParameter("@username", username),
new SqlParameter("@password", password)
});
}
کد لایه BLL :
public int userid { get; set; }
public string username{ get; set; }
public string password { get; set; }
public string roles { get; set; }
public string email { get; set; }
public static string GetUserRoleByusername(string Username){
return users.GetUserRoleByusername(Username);
}
public static string GetApproleByAppname(string applicationname)
{
return users.GetApproleByAppname(applicationname);
}
public static string CheckUsernameAndPasswordMatch(string username,string password)
{
return users.CheckUsernameAndPasswordMatch(username,passw ord);
}
وقتی دکمه login رو می زنم کلا قفل می کنه
ممنون می شم اگه یک نگاهی به کدها بندازید جاییش اگر ایراد داشت بهم بگید ؟؟:گیج::گیج: