2022-09-05 16:36:31 +08:00
|
|
|
|
using BLL;
|
|
|
|
|
|
using Model;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Web.Http;
|
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
using System.Web.Optimization;
|
|
|
|
|
|
using System.Web.Routing;
|
2024-12-02 17:51:43 +08:00
|
|
|
|
using WebAPI.Log;
|
2022-09-05 16:36:31 +08:00
|
|
|
|
|
|
|
|
|
|
namespace WebAPI
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class WebApiApplication : System.Web.HttpApplication
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected void Application_Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
|
|
|
GlobalConfiguration.Configure(WebApiConfig.Register);
|
|
|
|
|
|
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
|
|
|
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
|
|
|
|
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
|
|
|
|
|
BLL.Funs.ConnString = ConfigurationManager.AppSettings["ConnectionString"];
|
|
|
|
|
|
BLL.Funs.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
|
|
|
|
|
|
BLL.ErrLogInfo.DefaultErrLogFullPath = Server.MapPath("~/ErrLog.txt");
|
|
|
|
|
|
|
|
|
|
|
|
// 使api返回为json
|
|
|
|
|
|
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
|
2024-12-02 17:51:43 +08:00
|
|
|
|
GlobalConfiguration.Configuration.MessageHandlers.Add(new CustomMessageHandler());
|
2022-09-05 16:36:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder errLog = null;
|
|
|
|
|
|
Exception ex = null;
|
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
|
{
|
|
|
|
|
|
Sys_ErrLogInfo newErr = new Sys_ErrLogInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrLogId = SQLHelper.GetNewID()
|
|
|
|
|
|
};
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取错误类
|
|
|
|
|
|
ex = Server.GetLastError().InnerException;
|
|
|
|
|
|
if (ex == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ex = Server.GetLastError().GetBaseException();
|
|
|
|
|
|
}
|
|
|
|
|
|
errLog = new StringBuilder();
|
|
|
|
|
|
errLog.Append(String.Format(CultureInfo.InvariantCulture, "出错文件:{0}\r\n", Request.Url.AbsoluteUri));
|
|
|
|
|
|
newErr.ErrUrl = Request.Url.AbsoluteUri;
|
|
|
|
|
|
|
|
|
|
|
|
if (Request.UserHostAddress != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
errLog.Append(String.Format(CultureInfo.InvariantCulture, "IP地址:{0}\r\n", Request.UserHostAddress));
|
|
|
|
|
|
newErr.ErrIP = Request.UserHostAddress;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Session != null && Session["CurrUser"] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
errLog.Append(String.Format(CultureInfo.InvariantCulture, "操作人员:{0}\r\n", ((Model.Person_Persons)Session["CurrUser"]).PersonName));
|
|
|
|
|
|
newErr.UserName = ((Model.Person_Persons)Session["CurrUser"]).PersonId;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
if (errLog != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
db.Sys_ErrLogInfo.InsertOnSubmit(newErr);
|
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ErrLogInfo.WriteLog(newErr.ErrLogId, ex, errLog == null ? null : errLog.ToString());
|
|
|
|
|
|
Server.ClearError();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|