using Autofac; using Autofac.Integration.WebApi; using AutoMapper; using FreeSql; using KJD_Web.Repository; using KJD_Web.Utils; using MAX.Core.DependencyInjection; using MAX.Core.Logger; using MAX.Framework.Logger; using MySql.Data.MySqlClient; using NLog; using Store.Framework.DependencyInjection; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Reflection; using System.Web; using System.Web.Http; using System.Web.Security; using System.Web.SessionState; namespace KJD_Web { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { NLogger.Instance.Info("应用程序启动"); var container = ContainerConfig.BuildContainer(); // 让 Web API 用 Autofac 解析 Controller GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); ContainerConfig.BuildHangfire(GlobalConfiguration.Configuration.DependencyResolver); GlobalConfiguration.Configure(WebApiConfig.Register); } protected void Session_Start(object sender, EventArgs e) { } protected void Application_BeginRequest(object sender, EventArgs e) { if (Context.Request.Path == "/") { Context.Response.ContentType = "text/plain"; Context.Response.Write("Service is running."); Context.Response.End(); } string hPath = Request.Url.LocalPath.ToString(); //if (!hPath.Contains(".asmx") && hPath.Contains("/user/")) //{ //hPath = hPath.Replace("/user/", "/UserService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/shop/")) //{ //hPath = hPath.Replace("/shop/", "/ShopService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/update/")) //{ //hPath = hPath.Replace("/update/", "/UpdateService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/order/")) //{ //hPath = hPath.Replace("/order/", "/OrderService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/product/")) //{ //hPath = hPath.Replace("/product/", "/ProductService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/product_third/")) //{ //hPath = hPath.Replace("/product_third/", "/ProductThirdService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/price/")) //{ //hPath = hPath.Replace("/price/", "/PriceService.asmx/"); //Context.RewritePath(hPath); //} //if (!hPath.Contains(".asmx") && hPath.Contains("/bxx_user/")) //{ //hPath = hPath.Replace("/bxx_user/", "/BXXUserService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/bxx_shop/")) //{ //hPath = hPath.Replace("/bxx_shop/", "/BXXShopService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/update/")) //{ // hPath = hPath.Replace("/update/", "/UpdateService.asmx/"); // Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/bxx_product/")) //{ //hPath = hPath.Replace("/bxx_product/", "/BXXProductService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/bxx_product_third/")) //{ //hPath = hPath.Replace("/bxx_product_third/", "/BXXProductThirdService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/bxx_price/")) //{ //hPath = hPath.Replace("/bxx_price/", "/BXXPriceService.asmx/"); //Context.RewritePath(hPath); //} //if (!hPath.Contains(".asmx") && hPath.Contains("/dyxd_user/")) //{ //hPath = hPath.Replace("/dyxd_user/", "/DYUserService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/dyxd_shop/")) //{ //hPath = hPath.Replace("/dyxd_shop/", "/DYShopService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/update/")) //{ // hPath = hPath.Replace("/update/", "/UpdateService.asmx/"); // Context.RewritePath(hPath); //} //if (!hPath.Contains(".asmx") && hPath.Contains("/wxxd_user/")) //{ // //hPath = hPath.Replace("/wxxd_user/", "/WXUserService.asmx/"); // //Context.RewritePath(hPath, false); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/wxxd_shop/")) //{ // hPath = hPath.Replace("/wxxd_shop/", "/WXShopService.asmx/"); // Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/update/")) //{ // hPath = hPath.Replace("/update/", "/UpdateService.asmx/"); // Context.RewritePath(hPath); //} //if (!hPath.Contains(".asmx") && hPath.Contains("/wxxd_product/")) //{ //hPath = hPath.Replace("/wxxd_product/", "/WXProductService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/wxxd_order/")) //{ //hPath = hPath.Replace("/wxxd_order/", "/WXOrderService.asmx/"); //Context.RewritePath(hPath); //} //else if (!hPath.Contains(".asmx") && hPath.Contains("/wxxd_shop_revenue_statistics/")) //{ //hPath = hPath.Replace("/wxxd_shop_revenue_statistics/", "/WXShopRevenueStatistics.asmx/"); //Context.RewritePath(hPath); //} // 请求录制:捕获请求链接与请求内容,用于迁移后的回放校验 //try { ApiRequestLogger.BeginRequest(Context); } catch { } } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } protected void Application_EndRequest(object sender, EventArgs e) { // 请求录制:合并响应内容并落盘 //try { ApiRequestLogger.EndRequest(Context); } catch { } } protected void Application_Error(object sender, EventArgs e) { } protected void Session_End(object sender, EventArgs e) { } protected void Application_End(object sender, EventArgs e) { } } }