如何創(chuàng)建Global.asax文件?
如何創(chuàng)建Global.asax文件?
使用VWD 2008可以創(chuàng)建Global.asax文件。啟動VWD 2008打開某網(wǎng)站后,執(zhí)行【文件】【新建文件】命令,打開【添加新項】對話框.在【模板】選項中選擇【全局應(yīng)用程序類】選項(如果網(wǎng)站已經(jīng)建立就不會看到此項目)單擊【打開】按鈕就可以在Web網(wǎng)站中創(chuàng)建Global.asax文件.一個Web網(wǎng)站只能擁有一個Global.asax文件。
Global.asax文件主要是定義Web應(yīng)用程序的Application_Start(),Application_End(),Session_Start()和Session_End()等事件處理程序.
Global.asax文件的內(nèi)容框架如下:(廣州網(wǎng)頁設(shè)計培訓 http://www.goalq.com.cn/webdesign/)
<%Application Language="C#"%>
<script runt="server">
void Application_Start(object sender,EventArgs e)
{
//在應(yīng)用程序啟動時運行的代碼
}
void Application_End(object sender, EventArgs e)
{
//在應(yīng)用程序關(guān)閉時運行的代碼
}
void Application_Error(object sender, EventArgs e)
{
//在出現(xiàn)未處理的錯誤時運行的代碼
}
void Session_Start(object sender,EventArgs e)
{
//在新會話啟動時運行的代碼
}
void Session_End(object sender, EventArgs e)
{
//在會話結(jié)束時運行的代碼。
//注意:只有在Web.config文件中的sessionstate模式設(shè)置為
// InProc時,才會引發(fā)Session_End事件.如果會話模式
//設(shè)置為StateServer或SQLServer, Oil不會引發(fā)該事件。
}
</script>
標簽:如何創(chuàng)建Global.asax文件?