|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Configuration;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using System.Web.Routing;
|
|
|
using Memcached.ClientLibrary;
|
|
|
using log4net;
|
|
|
using DSWeb.Areas;
|
|
|
using System.Threading;
|
|
|
using System.Timers;
|
|
|
using DSWeb.Areas.Mobile.DAL;
|
|
|
using System.Net;
|
|
|
using System.IO;
|
|
|
using Quartz.Impl;
|
|
|
|
|
|
namespace DSWeb
|
|
|
{
|
|
|
public class Global : System.Web.HttpApplication
|
|
|
{
|
|
|
public static void RegisterRoutes(RouteCollection routes)
|
|
|
{
|
|
|
string ls = System.Configuration.ConfigurationSettings.AppSettings["isly"].ToString();
|
|
|
if (ls == "1")
|
|
|
{
|
|
|
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
|
|
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
|
|
|
routes.MapRoute(
|
|
|
"Default", //适用于虚拟主机,ext可以为ashx,aspx,ascx,asmx
|
|
|
"{controller}.{ext}/{action}/{id}",
|
|
|
new { controller = "Home", action = "Index", id = "" },
|
|
|
new[] { "DSWeb.Controllers" });
|
|
|
routes.MapRoute(
|
|
|
"Default2", //适用可以设置IIS或IIS版本为7.0以上
|
|
|
"{controller}/{action}/{id}",
|
|
|
new { controller = "Home", action = "Index", id = "" },
|
|
|
new[] { "DSWeb.Controllers" });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
protected void Application_Start(object sender, EventArgs e)
|
|
|
{
|
|
|
string ls = System.Configuration.ConfigurationSettings.AppSettings["isly"].ToString();
|
|
|
if (ls == "1")
|
|
|
{
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
RegisterRoutes(RouteTable.Routes);
|
|
|
}
|
|
|
|
|
|
StdSchedulerFactory.GetDefaultScheduler().Start();
|
|
|
AutoMapperConfig.Init();
|
|
|
|
|
|
//System.Timers.Timer evtTimer = new System.Timers.Timer(150000);
|
|
|
//evtTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnEvtTimer);
|
|
|
//evtTimer.Interval = 150000;
|
|
|
//evtTimer.Enabled = true;
|
|
|
|
|
|
//HomeService.HomeService.StoreMemcachedForCount();
|
|
|
|
|
|
////log4j日志记录
|
|
|
//log4net.Config.XmlConfigurator.Configure();//读取了配置文件中关于Log4Net配置信息.
|
|
|
////开启一个线程,扫描异常信息队列。
|
|
|
//string filePath = Server.MapPath("/Log/");
|
|
|
//ThreadPool.QueueUserWorkItem(( a ) =>
|
|
|
//{
|
|
|
// while (true)
|
|
|
// {
|
|
|
// //判断一下队列中是否有数据
|
|
|
// if (ExceptionAttribute.ExecptionQueue.Count() > 0)
|
|
|
// {
|
|
|
// Exception ex = ExceptionAttribute.ExecptionQueue.Dequeue();
|
|
|
// if (ex != null)
|
|
|
// {
|
|
|
// //将异常信息写到日志文件中。
|
|
|
// //string fileName = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
// //File.AppendAllText(filePath+fileName+".txt",ex.ToString(),System.Text.Encoding.UTF8);
|
|
|
// ILog logger = LogManager.GetLogger("errorMsg");
|
|
|
// logger.Error(ex.ToString());
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// //如果队列中没有数据,休息
|
|
|
// Thread.Sleep(3000);
|
|
|
// }
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// //如果队列中没有数据,休息
|
|
|
// Thread.Sleep(3000);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
//}, filePath);
|
|
|
|
|
|
//var appid = ConfigurationManager.AppSettings["appid"];
|
|
|
//if (appid!=null && appid.ToString()!="")
|
|
|
//{
|
|
|
// //每隔5个小时,刷新微信的AccessToken
|
|
|
// System.Timers.Timer myTimer = new System.Timers.Timer(1000 * 60*60*5);
|
|
|
|
|
|
// myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
|
|
|
|
|
|
// myTimer.Enabled = true;
|
|
|
|
|
|
// myTimer.AutoReset = true;
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
private static void OnEvtTimer(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
|
|
|
//定时运行服务
|
|
|
//c#让webservice定时执行
|
|
|
/*HomeService.HomeService.StoreMemcachedForCount("");
|
|
|
HomeService.HomeService.StoreMemcachedForList("");*/
|
|
|
// HomeService.NavigationService.StoreMemcached();
|
|
|
|
|
|
}
|
|
|
protected void Session_Start(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Application_BeginRequest(object sender, EventArgs e)
|
|
|
{
|
|
|
if (Context.Request.FilePath == "/") Context.RewritePath("Default.aspx");
|
|
|
}
|
|
|
|
|
|
protected void Application_AuthenticateRequest(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
|
{
|
|
|
Exception lastError = Server.GetLastError();
|
|
|
ExceptionAttribute.AddException(lastError);
|
|
|
//Server.Transfer("~/Error/FriendError.aspx");
|
|
|
}
|
|
|
|
|
|
protected void Session_End(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Application_End(object sender, EventArgs e)
|
|
|
{
|
|
|
#region 微信刷新AccessToken定时器关联
|
|
|
//下面的代码是关键,可解决IIS应用程序池自动回收的问题
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
//这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start
|
|
|
|
|
|
string url = "http://www.baidu.com";
|
|
|
|
|
|
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
|
|
|
|
|
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
|
|
|
|
|
|
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
void myTimer_Elapsed ( object source, ElapsedEventArgs e )
|
|
|
{
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
DBLog.Log(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":AutoTask is Working!");
|
|
|
|
|
|
TokenTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
|
|
|
DBLog.Log(ee.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void TokenTask ( )
|
|
|
{
|
|
|
//AccessTokenDAL.RefrashAccessToken();
|
|
|
}
|
|
|
}
|
|
|
} |