diff --git a/Base/Filter/AuthFilter.cs b/Base/Filter/AuthFilter.cs
index 2a654ed..290fa59 100644
--- a/Base/Filter/AuthFilter.cs
+++ b/Base/Filter/AuthFilter.cs
@@ -13,33 +13,46 @@ namespace NP.Base.Auth
{
public EMRole[] Roles { get; set; }
BaseController _base;
+
public bool IsFront { get; set; }
public override void OnActionExecuting(ActionExecutingContext context)
{
Controller currentControll = context.Controller as Controller;
_base = currentControll as BaseController;
- //if (_base.SUserInfo.UserNo > 0 && Array.Exists(Roles, el => el == GetEMRole(_base.SUserInfo.UserType)))
+
if (!IsFront)
{
- var cm = _base.GetMENUS.Where(w => w.usertype == _base.SUserInfo.UserType && w.menuurl.Equals(context.HttpContext.Request.Url.AbsolutePath)).OrderByDescending(od => od.menulevel).FirstOrDefault();
- if (cm != null
- || (_base.SUserInfo.UserNo > 0 && (context.HttpContext.Request.Url.AbsolutePath.Equals("/Home/Index/")
- || context.HttpContext.Request.Url.AbsolutePath.Equals("/Home/Index")
- || context.HttpContext.Request.Url.AbsolutePath.Equals("/Home/")
- || context.HttpContext.Request.Url.AbsolutePath.Equals("/Home")
- || context.HttpContext.Request.Url.AbsolutePath.Equals("/"))))
+ var cm = _base.GetMENUS
+ .Where(w => w.usertype == _base.SUserInfo.UserType && w.menuurl.Equals(context.HttpContext.Request.Url.AbsolutePath))
+ .OrderByDescending(od => od.menulevel)
+ .FirstOrDefault();
+
+ var absolutePath = context.HttpContext.Request.Url.AbsolutePath.ToLower();
+
+ if (cm != null || (_base.SUserInfo.UserNo > 0 && (absolutePath == "/" || absolutePath.StartsWith("/home"))))
{
_base.ViewBag.Title = (cm ?? new Model.Menu()).menuname ?? "Home";
_base.ViewBag.CMenu = cm;
_base.ViewBag.CMenuNo = (cm ?? new Model.Menu()).menuno;
_base.ViewBag.CHidden = (cm ?? new Model.Menu()).ishid;
+
var pmenu = (_base.GetMENUS.Where(w => w.menuno == (cm ?? new Model.Menu()).pmenuno).FirstOrDefault() ?? new Model.Menu());
_base.ViewBag.pmenuno = pmenu.ishid == 1 ? pmenu.pmenuno : pmenu.menuno;
_base.ViewBag.pmenunos = (cm ?? new Model.Menu()).menurout;
- //접속로그
- var rtn = System.Threading.Tasks.Task.Run(async() => Console.WriteLine(await _base.Dao.Log(
- new NP.Model.PageLog() { uno = _base.SUserInfo.UserNo, uip = _base.GetUserIP(), logsite = 0, menuno = _base.ViewBag.CMenuNo < 1 ? (int?)null : _base.ViewBag.CMenuNo, loginfo = _base.ViewBag.Title })));
+
+ // 접속로그 (2025-04-14 HS: 불필요한 2중 Task제거 후 await 구문으로 변경)
+ var rtn = System.Threading.Tasks.Task.Run(async () => await _base.Dao.Log(
+ new Model.PageLog()
+ {
+ uno = _base.SUserInfo.UserNo,
+ uip = _base.GetUserIP(),
+ logsite = 0,
+ menuno = _base.ViewBag.CMenuNo < 1 ? (int?)null : _base.ViewBag.CMenuNo,
+ loginfo = _base.ViewBag.Title
+ })
+ );
+
base.OnActionExecuting(context);
}
else
@@ -65,13 +78,12 @@ namespace NP.Base.Auth
{
switch (userType)
{
- case 99:
- return EMRole.Admin;
- case 1:
- return EMRole.Student;
+ case 99: return EMRole.Admin;
+ case 1: return EMRole.Student;
}
+
return EMRole.Anonymous;
}
}
-}
+}
\ No newline at end of file
diff --git a/Dao/CommonDao.cs b/Dao/CommonDao.cs
index 8415930..d370566 100644
--- a/Dao/CommonDao.cs
+++ b/Dao/CommonDao.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using NP.Model;
using System.Collections;
using NP.Dao.MyBatis;
+using MySql.Data.MySqlClient;
namespace NP.Dao
{
public partial class CommonDao : BaseDao
@@ -267,51 +268,44 @@ namespace NP.Dao
}
return 0;
}
+
+ ///
+ /// 접속로그 등록
+ ///
+ ///
+ ///
public async Task Log(PageLog log)
{
int rtn = 0;
- using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(NP.Frame.DaoFactory.Instance.DataSource.ConnectionString))
+
+ using (var conn = new MySqlConnection(Frame.DaoFactory.Instance.DataSource.ConnectionString))
{
try
{
- //int count = 0;
- MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand("insert into pagelog(logsite,userno,menuno,pno,loginfo,cdt,cno,udt,uno,uip)values(" + log.logsite + "," + log.uno + "," + (log.menuno == null ? "null" : log.menuno.ToString()) + "," + (log.pno == null ? "null" : log.pno.ToString()) + ",'" + (log.loginfo ?? "") + "',now()," + log.uno + ",now()," + log.uno + ",'" + log.uip + "')", conn);
- command.CommandType = System.Data.CommandType.Text;
- conn.Open();
- //conn.OpenAsync();
- //command.ExecuteNonQuery();
- rtn = (int) await command.ExecuteNonQueryAsync();
- //IAsyncResult result = command.BeginExecuteNonQuery(new AsyncCallback(logcompleted), command);
- //IAsyncResult result = command.BeginExecuteNonQuery();
- //while (!result.IsCompleted)
- //{
- // Console.WriteLine("Waiting ({0})", count++);
- // // Wait for 1/10 second, so the counter
- // // does not consume all available resources
- // // on the main thread.
- // System.Threading.Thread.Sleep(100);
- //}
- //Console.WriteLine("Command complete. Affected {0} rows.",
- // command.EndExecuteNonQuery(result));
- //command.EndExecuteNonQuery(result);
- }
- catch (MySql.Data.MySqlClient.MySqlException ex)
- {
- //Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message);
- }
- catch (InvalidOperationException ex)
- {
- //Console.WriteLine("Error: {0}", ex.Message);
+ await conn.OpenAsync();
+ using (var command = new MySqlCommand("insert into pagelog(logsite, userno, menuno, pno, loginfo, cdt, cno, udt, uno, uip) values (@logsite, @uno, @menuno, @pno, @loginfo, now(), @uno, now(), @uno, @uip)", conn))
+ {
+ command.Parameters.AddWithValue("@logsite", log.logsite);
+ command.Parameters.AddWithValue("@uno", log.uno);
+ command.Parameters.AddWithValue("@menuno", log.menuno ?? (object)DBNull.Value);
+ command.Parameters.AddWithValue("@pno", log.pno ?? (object)DBNull.Value);
+ command.Parameters.AddWithValue("@loginfo", log.loginfo ?? "");
+ command.Parameters.AddWithValue("@uip", log.uip);
+
+ rtn = await command.ExecuteNonQueryAsync();
+ }
}
catch (Exception ex)
{
- // You might want to pass these errors
- // back out to the caller.
- //Console.WriteLine("Error: {0}", ex.Message);
+ Console.WriteLine(ex.Message);
}
}
+
return rtn;
}
+
+
+
public int SavePay(Pay p, bool inlect, bool inlectsedate = false)
{
Trans();