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
|
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script RunAt="server">
void Application_Start(object sender, EventArgs e) {
log4net.Config.XmlConfigurator.Configure();
Logging.Logger.Info("Sample starting...");
}
void Application_End(object sender, EventArgs e) {
Logging.Logger.Info("Sample shutting down...");
// this would be automatic, but in partial trust scenarios it is not.
log4net.LogManager.Shutdown();
}
void Application_Error(object sender, EventArgs e) {
Logging.Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError());
}
void Application_BeginRequest(object sender, EventArgs e) {
Logging.Logger.DebugFormat("Processing {0} on {1} ", Request.HttpMethod, stripQueryString(Request.Url));
if (Request.QueryString.Count > 0) {
Logging.Logger.DebugFormat("Querystring follows: \n{0}", ToString(Request.QueryString));
}
if (Request.Form.Count > 0) {
Logging.Logger.DebugFormat("Posted form follows: \n{0}", ToString(Request.Form));
}
}
void Session_Start(object sender, EventArgs e) {
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e) {
// 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.
}
private static string ToString(NameValueCollection collection) {
using (StringWriter sw = new StringWriter()) {
foreach (string key in collection.Keys) {
sw.WriteLine("{0} = '{1}'", key, collection[key]);
}
return sw.ToString();
}
}
private static string stripQueryString(Uri uri) {
UriBuilder builder = new UriBuilder(uri);
builder.Query = null;
return builder.ToString();
}
</script>
|