using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace 全局應用程式類Global應用
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
//程式第一次運作;
}
protected void Session_Start(object sender, EventArgs e)
//Session第一次接入時觸發,可以實作線上使用者統計的代碼
protected void Application_BeginRequest(object sender, EventArgs e)
//頁面請求資料,可以用來實作圖檔防盜鍊,圖檔加水印,禁用IP位址等代碼
//禁用IP位址
//if (Request.UserHostAddress == "127.0.0.1")
//{
// Response.Write("您的IP位址被禁用,無法通路本站");
// Response.End();
//}
//圖檔防盜鍊,假設網站隻有jpg格式的圖檔
if (Request.Url.AbsolutePath.EndsWith(".jpg") && Request.UrlReferrer.Host != "localhost")
{
Response.WriteFile(Server.MapPath("Info.png"));
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
protected void Application_Error(object sender, EventArgs e)
//引發異常; 也可以在Web.config中配置錯誤頁,也可以在這裡寫代碼;
//使用 Server.GetLastError();擷取異常資訊,可以記錄到日志中;
Server.GetLastError();
protected void Session_End(object sender, EventArgs e)
protected void Application_End(object sender, EventArgs e)
}
}