[ Ognjen_NS @ 15.02.2006. 10:49 ] @
Citao sam u MSDN-u kreiranje ticketa za forms authentication (a video sam negde da je i mmix pojasnio). Problem je sledeci: Kada se ulogujem kao profesor, a zatim otvorim novi prozor i ulogujem se kao student ako cekam recimo na profesorovoj strani 1 minut, vratime strana na login (kao da obrishe cookie), a student radi. Ili nekad profesor i izdrzi do kraja. Hocu da profesor bude ulogovan 60 minuta......... Zbunjen sam totalno evo coda: Ovo je u GLobal.ascx : Code: void FormsAuthentication_OnAuthenticate(Object sender, System.Web.Security.FormsAuthenticationEventArgs e) { if (e.Context.Request.Cookies[".AUTHCOOKIE"]!= null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(e.Context.Request.Cookies[".AUTHCOOKIE"].Value); string[] roles = ticket.UserData.Split(';'); e.User = new GenericPrincipal(new GenericIdentity(ticket.Name, "FormsAuthentication"), roles); } } Ovo je u web configu (glavnom): Code: <authentication mode="Forms"> <forms name =".AUTHCOOKIE" loginUrl="Login.aspx"/> </authentication> <authorization> <deny users="?"/> </authorization> ovo je u loginu: Code: //proveravamo da li je user validan u ovom slucaju profesor private bool AuthenticatedP(string Username, string Password) { //kreiramo objekte adapter i table DataSet1TableAdapters.PredavacTableAdapter ProfAdapter = new DataSet1TableAdapters.PredavacTableAdapter(); DataSet1.PredavacDataTable ProfTabela = new DataSet1.PredavacDataTable(); //ocistimo tabelu za svaki slucaj ProfTabela.Clear(); //napunimo je ProfAdapter.FillByImeISifra(ProfTabela,Username,Password); if (ProfTabela.Rows.Count != 1) { return false; } else { return true; } } //proveravamo da li je user validan u ovom slucaju student private bool AuthenticatedS(string Username, string Password) { //kreiramo objekte adapter i table DataSet1TableAdapters.StudentTableAdapter StudAdapter = new DataSet1TableAdapters.StudentTableAdapter(); DataSet1.StudentDataTable StudTabela = new DataSet1.StudentDataTable(); //ocistimo tabelu za svaki slucaj StudTabela.Clear(); //napunimo je StudAdapter.FillByIndexiIme(StudTabela, Username,Password); if (StudTabela.Rows.Count != 1) { return false; } else { return true; } } protected void Button1_Click(object sender, EventArgs e) { bool isPersistent = false; //ako je profesor dodeli ulogu prof if (AuthenticatedP(TextBox1.Text, TextBox2.Text)) { //podesavamo role string userData = "Prof"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, TextBox1.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isPersistent, userData, FormsAuthentication.FormsCookiePath); //encriptujemo ticet string encTicket = FormsAuthentication.Encrypt(ticket); //kreiramo cookie Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); Response.Redirect("Profesori/Pocetna.aspx"); } else if (AuthenticatedS(TextBox1.Text, TextBox2.Text)) { //podesavamo role string userData = "Stud"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,TextBox1.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isPersistent, userData, FormsAuthentication.FormsCookiePath); //encriptujemo ticet string encTicket = FormsAuthentication.Encrypt(ticket); //kreiramo cookie Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); Response.Redirect("Studenti/Upload.aspx"); } else { Label3.Visible = true; TextBox1.Text = ""; TextBox2.Text = ""; } } } Pomagajte:) |