如何在 net core 5 中使用 HttpContext.Current(没有 necromenssing)
how to use HttpContext.Current in net core 5 (no necromenssing)
在我们使用 net 5 之前,我们使用 net framework。
// 网络框架
ClsLog.WriteLog(HttpContex.Current, GetType(), "GetManualWeightData", ActionType.Action_Read, model.UID, model, clsResponse, clsResponse.ErrorMsg, model.LogCode);
//
但现在我们使用 net 5 而 net 5 不能使用电流...
如何代替“current”?
+
public class ClsLog
{
public static void WriteLog(HttpContext current, Type type, string strMethodName, string strActionType, string strUID, object strParam, object strResponse, string strErrorMsg = "", string strLogCode = "")
{
string strLocalIP = "";
string strBrowser = "";
string strMemID = "";
string strCustomerID = "";
if (current != null)
{
//strLocalIP = current.Session("LocalIP"] + "";
//strBrowser = current.Session["BrowserInfo"] + "";
//strMemID = current.Session["LogID"] + "";
//strCustomerID = current.Session["CustomerID"] + "";
}
try
{
Task.Run(() => ClsWriteLog.getInstance().WriteLogServer(new ClsVariableAppLog("AppAPILog", strLocalIP, strBrowser, strMemID, strCustomerID, type.Module.Name, strMethodName, strUID, strActionType, type.FullName, strErrorMsg, strParam, strResponse, strLogCode)));
//await ClsWriteLog.getInstance().WriteLogServer(new ClsVariableAppLog("AppAPILog", strLocalIP, strBrowser, strMemID, strCustomerID, type.Module.Name, strMethodName, strUID, strActionType, type.FullName, strErrorMsg, strParam, strResponse));
}
catch (Exception ex)
{
Trace.WriteLine("LogError - " + ex.Message);
}
}
}```
在我们使用 net 5 之前,我们使用 net framework。
// 网络框架
ClsLog.WriteLog(HttpContex.Current, GetType(), "GetManualWeightData", ActionType.Action_Read, model.UID, model, clsResponse, clsResponse.ErrorMsg, model.LogCode);
//
但现在我们使用 net 5 而 net 5 不能使用电流... 如何代替“current”?
+
public class ClsLog
{
public static void WriteLog(HttpContext current, Type type, string strMethodName, string strActionType, string strUID, object strParam, object strResponse, string strErrorMsg = "", string strLogCode = "")
{
string strLocalIP = "";
string strBrowser = "";
string strMemID = "";
string strCustomerID = "";
if (current != null)
{
//strLocalIP = current.Session("LocalIP"] + "";
//strBrowser = current.Session["BrowserInfo"] + "";
//strMemID = current.Session["LogID"] + "";
//strCustomerID = current.Session["CustomerID"] + "";
}
try
{
Task.Run(() => ClsWriteLog.getInstance().WriteLogServer(new ClsVariableAppLog("AppAPILog", strLocalIP, strBrowser, strMemID, strCustomerID, type.Module.Name, strMethodName, strUID, strActionType, type.FullName, strErrorMsg, strParam, strResponse, strLogCode)));
//await ClsWriteLog.getInstance().WriteLogServer(new ClsVariableAppLog("AppAPILog", strLocalIP, strBrowser, strMemID, strCustomerID, type.Module.Name, strMethodName, strUID, strActionType, type.FullName, strErrorMsg, strParam, strResponse));
}
catch (Exception ex)
{
Trace.WriteLine("LogError - " + ex.Message);
}
}
}```