using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
/// <summary>
/// Summary description for Module
/// </summary>
//1.繼承IHttpModule類,實現接口成員
namespace JudgeSessionOutTime
{
public class Module : IHttpModule, IRequiresSessionState
{
public void Dispose()
{
// throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
//原因:這個事件時,Session尚未創建。要先指定類型在判斷地址欄是否存在
//context.BeginRequest += new EventHandler(context_BeginRequest);
context.AcquireRequestState += (obj, e) =>
{
var app = (HttpApplication)obj;
var url = app.Request.RawUrl;
//還要先判斷下請求類型
if (url.IndexOf(".aspx") > 0)
{
//判斷非UserLogin請求 防止進入死循環(此網頁包含重定向循環)
if (url.IndexOf("Login.aspx") < 0)
{
if (url.IndexOf("GetValidateCode") > 0 || url.IndexOf("UserRegister") > 0 || url.IndexOf("notify_url") > 0 || url.IndexOf("return_url") > 0)//排除過濾選項
{
}
else if (app.Context.Session["admin"] == null)
{
//app.Response.Redirect("../Login.aspx", false);
string loginURl ="/Login.aspx";
// Utility.Jscript.alert("本次登錄已經超時,請重新登錄系統");
app.Context.Response.Write(" <script>top.location='" + loginURl + "' ;</script>");
app.Context.Response.End();
}
}
}
};
}
}
}