Global
概述
Global
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["Title"] = "Builder
}
protected void Session_Start(Object sender
Session["startValue"] =
}
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
}
這個例子只是很簡單地使用了一些Global
這裡是前面的例子相應的 VB
Sub Application_Start(ByVal sender As Object
Application("Title") = "Builder
End Sub
Sub Session_Start(ByVal sender As Object
Session("startValue") =
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object
EventArgs)
’ Extract the forms authentication cookie
Dim cookieName As String
cookieName = FormsAuthentication
Dim authCookie As HttpCookie
authCookie = Context
If (authCookie Is Nothing) Then
’ There is no authentication cookie
Return
End If
Dim authTicket As FormsAuthenticationTicket
authTicket = Nothing
Try
authTicket = FormsAuthentication
Catch ex As Exception
’ Log exception details (omitted for simplicity)
Return
End Try
Dim roles(
roles(
roles(
Dim id As FormsIdentity
id = New FormsIdentity(authTicket)
Dim principal As GenericPrincipal
principal = New GenericPrincipal(id
’ Attach the new principal object to the current HttpContext object
Context
End Sub
Sub Application_Error(ByVal sender As Object
Response
End Sub
資源
Global
From:http://tw.wingwit.com/Article/program/net/201311/14473.html