2009/02/09

.Net 新手之global.asax - application 的用法 (2)

Application 的執行流程,我參考這一個網站的 sample 做一些改寫,並且標上順序...以方便我未來寫程式時的參考資料。

<%@ Application Language="C#" %>

<script runat="server">

void Application_Start(Object sender, EventArgs e) {
Application.Set("Time", System.DateTime.Now);
}

// 1.
void Application_BeginRequest(Object sender, EventArgs e)
{
Response.Write("<b>Process</b>");
Response.Write("Request is starting...<br>");
}

// 2.
void Application_AuthorizeRequest(Object sender, EventArgs e)
{
Response.Write("Authorizing request...<br>");
}

// 3.
void Application_ResolveRequestCache(Object sender, EventArgs e)
{
Response.Write("Resolving request cache...<br>");
}

// 4.
void Session_Start(Object sender, EventArgs e)
{
Response.Write("Session is starting...<br>");
}

// 5.
void Application_AcquireRequestState(Object sender, EventArgs e)
{
Response.Write("Acquiring request session state" + "...<br>");
}

// 6.
void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
Response.Write("Pre Request handler executed...<br>");
}

// 7. 已處理完後的流程
void Application_PostRequestHandlerExecute(Object sender, EventArgs e)
{
Response.Write("Post Request handler executed...<br>");
}


// 8.
void Application_ReleaseRequestState(Object sender, EventArgs e)
{
Response.Write("Releasing request state...<br>");
}

// 9.
void Application_UpdateRequestCache(Object sender, EventArgs e)
{
Response.Write("Updating request cache...<br>");
}

void Application_AuthenticateRequest(Object sender, EventArgs e)
{
Application.Set("Time", System.DateTime.Now);
}

// 10.
void Application_EndRequest(Object sender, EventArgs e)
{
Response.Write("Request is ending...<br>");
}

// 11.
void Application_PreSendRequestHeaders(Object sender, EventArgs e)
{
Response.Write("Receiving request headers...<br>");
}

// 12.
void Application_PreSendRequestContent(Object sender, EventArgs e)
{
Response.Write("Receiving request content...<br>");
}

// Exception
void Application_Error(Object sender, EventArgs e)
{
Response.Write( " is authenticating request...<br>");
}

</script>

沒有留言: