Files
Web_AuthorityManagement_Mvc…/UI/Global.asax.cs
2025-11-20 09:51:24 +08:00

87 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Models;
using Models.ModelItems;
using Models.View;
using Services.Cache;
using Services.Manager;
using Services.Tool;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace UI
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
//注入定时任务
TimingService.MyRegistry.GoWork();
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
try
{
//初始化数据
//刷新缓存
CacheHelp.Updatesys(null);
}
catch (Exception ex)
{
Logs.WriteTimingUDPLog(ex.ToString());
}
}
protected void Application_End()
{
try
{
string strURL = ConfigHelper.GetConfigString("Homeurl") ?? "";
Logs.WriteTimingUDPLog("进程即将被IIS回收" + strURL);
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.Stream stream = wc.OpenRead(strURL);
System.IO.StreamReader reader = new StreamReader(stream);
string html = reader.ReadToEnd();
if (!string.IsNullOrWhiteSpace(html))
{
Logs.WriteTimingUDPLog("唤醒程序成功");
}
reader.Close();
reader.Dispose();
stream.Close();
stream.Dispose();
wc.Dispose();
}
catch (Exception ex)
{
Logs.WriteTimingUDPLog("唤醒异常" + ex.Message );
}
}
protected void Application_Error(Object sender, EventArgs e)
{
Exception lastError = Server.GetLastError();//获取异常
if (lastError != null)
{
//异常信息
string strExceptionMessage = string.Empty;
//对HTTP 404做额外处理其他错误全部当成500服务器错误
HttpException httpError = lastError as HttpException;
//得到错误信息,可以写到日志里
LogHelp.WriteExceptionLog(lastError);
//一定要调用Server.ClearError()否则会触发错误详情页(就是黄页)
//Server.ClearError();
}
}
}
}