Files
g.hnyhua.cn/Mtxfw.shop/Global.asax.cs

136 lines
4.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Security;
using System.Timers;
namespace Mtxfw.shop
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
SetTimer();
}
protected void Session_Start(object sender, EventArgs e)
{
//Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID.ToString();
//Response.Cookies["ASP.NET_SessionId"].Domain = ".dhshw.cn";
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
var Request = HttpContext.Current.Request;
var Response = HttpContext.Current.Response;
/* Fix for the Flash Player Cookie bug in Non-IE browsers.
* Since Flash Player always sends the IE cookies even in FireFox
* we have to bypass the cookies by sending the values as part of the POST or GET
* and overwrite the cookies with the passed in values.
*
* The theory is that at this point (BeginRequest) the cookies have not been read by
* the Session and Authentication logic and if we update the cookies here we'll get our
* Session and Authentication restored correctly
*/
try
{
string session_param_name = "ASPSESSID";
string session_cookie_name = "ASP.NET_SESSIONID";
if (HttpContext.Current.Request.Form[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
}
else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
}
}
catch (Exception)
{
Response.StatusCode = 500;
Response.Write("Error Initializing Session");
}
}
static void UpdateCookie(string cookie_name, string cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
if (cookie == null)
{
cookie = new HttpCookie(cookie_name);
//SWFUpload 的Demo中给的代码有问题需要加上cookie.Expires 设置才可以
cookie.Expires = DateTime.Now.AddYears(1);
HttpContext.Current.Request.Cookies.Add(cookie);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
Mtxfw.Utility.Authentication Action = new Mtxfw.Utility.Authentication();
if (Action.IsAuthenticated)
{
Action.RequestAuthenticate(sender);
}
}
protected void Application_Error(object sender, EventArgs e)
{
//获取当前异常根源
Exception ex = HttpContext.Current.Server.GetLastError().GetBaseException();
Mtxfw.Utility.Error MyError = new Mtxfw.Utility.Error(ex);
MyError.Write();
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
public static void SetTimer()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimer);
aTimer.Interval = 60000;
aTimer.Enabled = true;
aTimer.Start();
}
public static void OnTimer(Object source, ElapsedEventArgs e)
{
DateTime dt = DateTime.Now;
DayOfWeek day = dt.DayOfWeek;
string dayString = day.ToString();
//if (dayString == "Saturday")
//{
if (dt.Hour >= 23 && dt.Minute >= 30)
{
Mtxfw.DAL.user_Results_jl3 daojl3 = new Mtxfw.DAL.user_Results_jl3();
int Countr = daojl3.GetCount("utype='5' And DateDiff(day,addtime,getdate())=0");
if (Countr == 0)
{
Model.user_Results_jl3 mjl3 = new Model.user_Results_jl3();
mjl3.addtime = DateTime.Now;
mjl3.utype = "5";
new DAL.user_Results_jl3().Add(mjl3);
Mtxfw.DAL.MemberStatistics.JiangLiJS(1);
//Mtxfw.DAL.MemberStatistics.ChouJiangJS();
}
}
//}
}
}
}