LoginMaster.aspx.cs

דף זה הוא הקוד מאחור של LoginMaster.aspx
 avatar
user_2706180
csharp
a month ago
1.6 kB
2
Indexable
Never
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services.Description;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YoadMadrid.Pages
{
    public partial class WebForm11 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session == null && (bool)Session["Login"])
            {
                Response.Redirect("/Pages/MainMaster.aspx");
            }
            if (IsPostBack)
            {
                string SQLStr = $"SELECT * FROM " + Helper.tblName +
                    $" WHERE Username='{Request.Form["Username"]}' AND Password = '{Request.Form["Password"]}'";
                DataSet ds = Helper.RetrieveTable(SQLStr);
                if (ds.Tables[Helper.tblName].Rows.Count > 0)
                {
                    Session["Username"] = Request.Form["Username"];
                    Session["Login"] = true;                            
                    Session["Admin"] = ds.Tables[0].Rows[0]["Admin"];   
                    test.InnerHtml = "";
                    Response.Redirect("/Pages/MainMaster.aspx");
                }

                else 
                {
                    Session["Username"] = "Guest";
                    Session["Login"] = false;
                    Session["Admin"] = false;
                    test.InnerHtml = "Unknown Username or Password";
                }
            }
        }
    }
}
Leave a Comment