abbott_2024_event/BackEnd/Login.aspx.cs

77 lines
2.3 KiB
C#

using Dapper;
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 abbott_2024_event;
namespace abbott_2024_event.BackEnd
{
public partial class Login : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString"));
protected void Page_Load(object sender, EventArgs e)
{
string myIP = globalClass.GetIPAddress();
if (myIP == "::1")
{
myIP = "127.0.0.1";
}
Boolean isAllow = false;
if (myIP == "127.0.0.1")
{
isAllow = true;
}
ipTable ipTable = conn.QueryFirstOrDefault<ipTable>("select * from ipTable where ipTable_address = @ipTable_address", new { ipTable_address = myIP });
if (ipTable != null) {
isAllow = true;
}
string myIP_2 = myIP.Substring(0, myIP.LastIndexOf('.')) + ".*";
autoBindDataTable objAllow2 = new autoBindDataTable(string.Format("select * from ipTable where ipTable_address = '{0}'", myIP_2));
if (objAllow2.dataRows.Count > 0)
{
isAllow = true;
}
string myIP_3 = myIP_2.Substring(0, myIP_2.Replace(".*", "").LastIndexOf('.')) + ".*.*";
autoBindDataTable objAllow3 = new autoBindDataTable(string.Format("select * from ipTable where ipTable_address = '{0}'", myIP_3));
if (objAllow3.dataRows.Count > 0)
{
isAllow = true;
}
string myIP_4 = myIP.Substring(0, myIP.IndexOf('.')) + ".*.*.*";
autoBindDataTable objAllow4 = new autoBindDataTable(string.Format("select * from ipTable where ipTable_address = '{0}'", myIP_4));
if (objAllow4.dataRows.Count > 0)
{
isAllow = true;
}
objAllow2.disConnection();
objAllow3.disConnection();
objAllow4.disConnection();
conn.Close();
if (isAllow == false)
{
Response.Redirect("auth-error-v3.html?ip=" + myIP);
return;
}
}
}
}