abbott_2024_event/BackEnd/Main.Master.cs

72 lines
2.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;
}
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.html?isLogout=true");
return;
}
}
}
}