summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdRelyingPartyWebFormsVB/Global.asax.vb
blob: 60ab0cc278f758901da2e5d83a0e6e3c5a6cab9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Imports System
Imports System.Collections.Specialized
Imports System.Configuration
Imports System.IO
Imports System.Text
Imports System.Web
Imports DotNetOpenAuth.ApplicationBlock
Imports DotNetOpenAuth.OAuth
Imports OpenIdRelyingPartyWebFormsVB

Public Class Global_asax
	Inherits HttpApplication

	Public Shared Logger As log4net.ILog = log4net.LogManager.GetLogger(GetType(Global_asax))

	Friend Shared LogMessages As StringBuilder = New StringBuilder

	Public Shared Function CollectionToString(ByVal collection As NameValueCollection) As String
		Dim sw As StringWriter = New StringWriter
		For Each key As String In collection.Keys
			sw.WriteLine("{0} = '{1}'", key, collection(key))
		Next
		Return sw.ToString
	End Function

	Protected Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
		log4net.Config.XmlConfigurator.Configure()
		Logger.Info("Sample starting...")
	End Sub

	Protected Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
		Logger.Info("Sample shutting down...")
		' this would be automatic, but in partial trust scenarios it is not.
		log4net.LogManager.Shutdown()
	End Sub

	Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
		' System.Diagnostics.Debugger.Launch();
		Logger.DebugFormat("Processing {0} on {1} ", Request.HttpMethod, stripQueryString(Request.Url))
		If (Request.QueryString.Count > 0) Then
			Logger.DebugFormat("Querystring follows: " & vbLf & "{0}", CollectionToString(Request.QueryString))
		End If
		If (Request.Form.Count > 0) Then
			Logger.DebugFormat("Posted form follows: " & vbLf & "{0}", CollectionToString(Request.Form))
		End If
	End Sub

	Protected Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
		Logger.DebugFormat("User {0} authenticated.", (Not (HttpContext.Current.User) Is Nothing))
		'TODO: Warning!!!, inline IF is not supported ?
	End Sub

	Protected Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)

	End Sub

	Protected Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
		Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError)
	End Sub

	Private Shared Function stripQueryString(ByVal uri As Uri) As String
		Dim builder As UriBuilder = New UriBuilder(uri)
		builder.Query = Nothing
		Return builder.ToString
	End Function
End Class