PDA

View Full Version : سوال: رفع مشکل login با تشخیص هویت به کمک شما ؟؟؟



Fartaj
سه شنبه 16 خرداد 1391, 18: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 رو می زنم کلا قفل می کنه

ممنون می شم اگه یک نگاهی به کدها بندازید جاییش اگر ایراد داشت بهم بگید ؟؟:گیج::گیج:

Fartaj
چهارشنبه 17 خرداد 1391, 08:07 صبح
جان ما هرکی می تونه کمک کنه جای دوری نمی ره حداقل نمی خواین کد بگین بگین کجاش ایراد داره برم روش کار کنم

مشکل اینجاست که وقتی login رو می زنم ارور webdev.webserver40.exe has stopped working می ده من حدس می زنم ایراد از تو کدهام هست

حرفه ای ها خواهشا نزارین تا اینجا اومدم ناامید بشم

fakhravari
جمعه 19 خرداد 1391, 20:38 عصر
این اخطار من برخوردن و از نبودن iis
شما یک بار تست کنید iis پاک کنید و دوباره نصب کنید
دوستان اگر اطلاعاتی دارن ممنون میشم کمک کنند.