Note: I'm using ASP.NET Core Web Application (.NET Framework) and C# and SQL Server I need to specify each admin and user description in database and to show it on MainPage every time I give a new description or remove it.
This is my Login Page:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
namespace WebApplication2
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LoginBtn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;Initial Catalog=Users;Integrated Security=True");
con.Open();
string query = "SELECT username, password FROM UsersRole WHERE username = '" + TxTUser.Text + "' and password = '" + TxTPass.Text + "'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
LabelMSG.Text = "You have Successfully Logged in!";
Response.Redirect("MainPage.aspx");
}
else
{
LabelMSG.Text = "Please Check your username or password!";
}
con.Close();
}
}
}
And this is my MainPage:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="WebApplication2.MainPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<nav>
<ul>
<li id="item1"><a href="#">Accounting</a></li>
<li id="item2"><a href="#">IT</a></li>
<li id="item3"><a href="#">Policies</a></li>
<li id="item4"><a href="#">Sales</a></li>
<li id="item5"><a href="#">Marketing</a></li>
<li id="item6"><a href="#">Equipment</a></li>
<li id="item7"><a href="#">Transportation</a></li>
<li id="item8"><a href="#">Printer</a></li>
<li id="item9"><a href="#">Cashier</a></li>
<li id="item10"><a href="#">HR</a></li>
</ul>
</nav>
</body>
</html>