Global
Global
· Application_Init
· Application_Disposed
· Application_Error
· Application_Start
· Application_End
· Application_BeginRequest
· Application_EndRequest
· Application_PreRequestHandlerExecute
· Application_PostRequestHandlerExecute
· Applcation_PreSendRequestHeaders
· Application_PreSendContent
· Application_AcquireRequestState
· Application_ReleaseRequestState
· Application_ResolveRequestCache
· Application_UpdateRequestCache
· Application_AuthenticateRequest
· Application_AuthorizeRequest
· Session_Start
· Session_End
使用這些事件的一個關鍵問題是知道它們被觸發的順序
· Application_BeginRequest
· Application_AuthenticateRequest
· Application_AuthorizeRequest
· Application_ResolveRequestCache
· Application_AcquireRequestState
· Application_PreRequestHandlerExecute
· Application_PreSendRequestHeaders
· Application_PreSendRequestContent
· <<執行代碼>>
· Application_PostRequestHandlerExecute
· Application_ReleaseRequestState
· Application_UpdateRequestCache
· Application_EndRequest
這些事件常被用於安全性方面
protected void Application_Start(Object sender
Application[
}
protected void Session_Start(Object sender
Session[
}
protected void Application_AuthenticateRequest(Object sender
// Extract the forms authentication cookie
string cookieName = FormsAuthentication
HttpCookie authCookie = Context
if(null == authCookie) {
// There is no authentication cookie
return;
}
FormsAuthenticationTicket authTicket = null;
try {
authTicket = FormsAuthentication
} catch(Exception ex) {
// Log exception details (omitted for simplicity)
return;
}
if (null == authTicket) {
// Cookie failed to decrypt
return;
}
// When the ticket was created
// a pipe delimited string of role names
string[
roles[
roles[
// Create an Identity object
FormsIdentity id = new FormsIdentity( authTicket );
// This principal will flow throughout the request
GenericPrincipal principal = new GenericPrincipal(id
// Attach the new principal object to the current HttpContext object
Context
}
protected void Application_Error(Object sender
Response
}
From:http://tw.wingwit.com/Article/program/net/201311/13336.html