99 lines
3.1 KiB
C#
99 lines
3.1 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;
|
|
|
|
namespace abbott_2024_event.BackEnd
|
|
{
|
|
|
|
public partial class Main : System.Web.UI.MasterPage
|
|
{
|
|
SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString"));
|
|
public authToken authToken;
|
|
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;
|
|
}
|
|
|
|
if (isAllow == false)
|
|
{
|
|
Response.Redirect("auth-error-v3.html");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
authToken = new authToken();
|
|
|
|
if (authToken.user_isLogin == false) {
|
|
HttpCookie tokenCookie = (HttpContext.Current.Request.Cookies["token"] == null) ? null : HttpContext.Current.Request.Cookies["token"];
|
|
HttpCookie idCookie = (HttpContext.Current.Request.Cookies["id"] == null) ? null : HttpContext.Current.Request.Cookies["id"];
|
|
|
|
HttpContext.Current.Response.Cookies["token"].Expires = DateTime.Now.AddDays(-1);
|
|
|
|
if (tokenCookie != null) {
|
|
tokenCookie.Expires = DateTime.Now.AddDays(-10);
|
|
tokenCookie.Values.Clear();
|
|
|
|
HttpContext.Current.Response.Cookies.Set(tokenCookie);
|
|
|
|
HttpContext.Current.Response.Cookies.Add(new HttpCookie("token", ""));
|
|
}
|
|
|
|
|
|
|
|
Response.Redirect("Login.aspx?isLogout=true");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |