A friend of mine came to me and wanted to know how to access members of global.asax in 2.0 (the big difference between 2.0 and 1.x is that the <script> statements have been applied to the file, which makes it feel a bit different). This is how (one odd thing I noted is that when I reference a member of this class from my code-behind, VS appears a bit behind the game on updating its internal references - therefore, intellisense appears missing and (once) the compiler failed to see my variable until I went back to the .asax file, re-saved it, and then went back to the .vb file!
Something feels almost counter-productive in this new direction taken with the .asax file, I'm not even sure why they did this....
In the global.asax file:
<%@ Application Language="VB" %>
<script runat="server">
Public Shared Sub MyCallBackMethod()
End Sub
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
</script>
In your code-behind:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Global.ASP.global_asax.MyCallBackMethod()
End Sub
End Class