master sayfası—-
protected void Page_Load(object sender, EventArgs e) { if (Session["KullaniciAdi"] != null) { LblKullanici.Text = "Hoş geldin, " + Session["KullaniciAdi"].ToString(); BtnCikis.Visible = true; BtnGiris.Visible = false; } else { LblKullanici.Text = ""; BtnCikis.Visible = false; BtnGiris.Visible = true; } } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("giris.aspx"); } protected void BtnCikis_Click(object sender, EventArgs e) { Session.Abandon(); Response.Redirect("giris.aspx"); }
giriş yap sayfası—
protected void Button1_Click(object sender, EventArgs e) { string email = TextBox1.Text.Trim(); string sifre = TextBox2.Text.Trim(); // Veritabanı bağlantı cümlesi (Kendi SQL bağlantını yaz) string connectionString = "Data Source=DESKTOP-3S3IQ27\\SQLEXPRESS;Initial Catalog=uye;Integrated Security=True"; using (SqlConnection con = new SqlConnection(connectionString)) { string query = "SELECT AdSoyad, Rol FROM uye WHERE Eposta = @Eposta AND Sifre = @Sifre"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@Eposta", email); cmd.Parameters.AddWithValue("@Sifre", sifre); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) // Kullanıcı bulundu mu? { // Doğru bilgileri alalım string kullaniciAdi = reader["AdSoyad"].ToString(); string rol = reader["Rol"].ToString(); // Session'a doğru bilgileri kaydedelim Session["KullaniciAdi"] = kullaniciAdi; Session["Rol"] = rol; reader.Close(); // Reader'ı kapatalım // Yönlendirme yap if (rol == "Admin") { Response.Redirect("Yonetim.aspx"); // Admin yönetim sayfasına gider } else { string script = "Swal.fire({title: 'Başarılı!', text: 'Hoş geldin, " + kullaniciAdi + "!', icon: 'success'}).then((value) => { window.location='Default.aspx'; });"; ScriptManager.RegisterStartupScript(this, GetType(), "sweetalert", script, true); Response.Redirect("Default.aspx"); // Normal kullanıcı anasayfaya gider } } else { Label1.Text = "Kullanıcı adı veya şifre yanlış!"; } reader.Close(); } }
yonetim sayfası —
protected void Page_Load(object sender, EventArgs e) { if (Session["Rol"] == null || string.IsNullOrEmpty(Session["Rol"].ToString()) || Session["Rol"].ToString() != "Admin") { string message = "Yetkili Kişi Değilsiniz!"; ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('" + message + "');", true); Response.Redirect("giris.aspx"); } if (Session["KullaniciAdi"] != null) { lblHosgeldin.Text = "Hoşgeldin, " + Session["KullaniciAdi"].ToString(); } }