天猫精灵背景音乐 ,官方文档 上的设置接口不管用,经过询问使用 另一个接口,完美解决
This commit is contained in:
@@ -98,6 +98,29 @@ namespace WebSite
|
||||
// 在应用程序启动时调用
|
||||
PreHot();
|
||||
log4net.Config.XmlConfigurator.Configure();//初始化log4net
|
||||
// 全局异常捕获,避免未处理异常导致进程崩溃
|
||||
AppDomain.CurrentDomain.UnhandledException += (s, args) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ex = args.ExceptionObject as Exception;
|
||||
if (ex != null)
|
||||
{
|
||||
logger.Error("UnhandledException:" + ex.Message);
|
||||
logger.Error(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
};
|
||||
TaskScheduler.UnobservedTaskException += (s, args) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Error("UnobservedTaskException:" + args.Exception.ToString());
|
||||
args.SetObserved();
|
||||
}
|
||||
catch { }
|
||||
};
|
||||
SetInitAccount();
|
||||
StartHostServer();
|
||||
//StartHostServerNew();
|
||||
@@ -201,10 +224,15 @@ namespace WebSite
|
||||
var T = sender as Timer;
|
||||
try
|
||||
{
|
||||
// 防止重入
|
||||
T.Stop();
|
||||
double d = CPUData.GetCPU();
|
||||
DataTongJi.CPU_Data.Add(d);
|
||||
T.Start();
|
||||
// 简单的上限保护,避免长期积累导致内存膨胀
|
||||
//if (DataTongJi.CPU_Data.Count > 1000)
|
||||
//{
|
||||
// DataTongJi.CPU_Data = new System.Collections.Concurrent.ConcurrentBag<double>();
|
||||
//}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -212,6 +240,7 @@ namespace WebSite
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 恢复计时器
|
||||
T.Start();
|
||||
}
|
||||
}
|
||||
@@ -773,6 +802,10 @@ namespace WebSite
|
||||
var ip = Request.UserHostAddress;
|
||||
var url = Request.Url.AbsolutePath.ToLower();
|
||||
|
||||
// 定期清理恶意IP记录,避免字典无限增长
|
||||
var nowUtc = DateTime.UtcNow;
|
||||
CleanupIpRecordIfNeeded(nowUtc);
|
||||
|
||||
// 定义要拦截的路径模式
|
||||
var maliciousPatterns = new[]
|
||||
{
|
||||
@@ -837,10 +870,40 @@ namespace WebSite
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 超过统计窗口则重置计数窗口
|
||||
if ((now - info.FirstRequest).TotalMinutes >= 1)
|
||||
{
|
||||
info.FirstRequest = now;
|
||||
info.RequestCount = 1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 恶意IP记录清理节流控制
|
||||
private static DateTime _lastIpCleanup = DateTime.MinValue;
|
||||
private static readonly TimeSpan _ipCleanupInterval = TimeSpan.FromMinutes(1);
|
||||
private static readonly TimeSpan _ipRetention = TimeSpan.FromMinutes(10);
|
||||
|
||||
private static void CleanupIpRecordIfNeeded(DateTime nowUtc)
|
||||
{
|
||||
if ((nowUtc - _lastIpCleanup) < _ipCleanupInterval) return;
|
||||
_lastIpCleanup = nowUtc;
|
||||
try
|
||||
{
|
||||
foreach (var kv in _ipRequests.ToArray())
|
||||
{
|
||||
var info = kv.Value;
|
||||
if ((nowUtc - info.LastRequest) > _ipRetention)
|
||||
{
|
||||
RequestInfo removed;
|
||||
_ipRequests.TryRemove(kv.Key, out removed);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private class RequestInfo
|
||||
{
|
||||
public RequestInfo()
|
||||
|
||||
Reference in New Issue
Block a user