forked from tianqiq/StaticHtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpModule.cs
More file actions
64 lines (58 loc) · 1.77 KB
/
Copy pathHttpModule.cs
File metadata and controls
64 lines (58 loc) · 1.77 KB
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
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Diagnostics;
namespace StaticHtml
{
/// <summary>
/// StaticHtmlHttpModule
/// </summary>
public class HttpModule : IHttpModule
{
#region IHttpModule 成员
private readonly static StaticHtmlSection htmlSection = System.Configuration.ConfigurationManager.GetSection("staticHtml") as StaticHtmlSection;
HtmlStaticCore core;
public void Init(HttpApplication context)
{
try
{
if (htmlSection.Run == "on")
{
core = HtmlStaticCore.GetInstance(htmlSection);
context.BeginRequest += new EventHandler(context_BeginRequest);
LogHelp.Info("int success! ");
}
else
{
LogHelp.Warn("run off! 请在staticHtml节点中添加属性run=\"on\" on:启用 off:关闭");
}
}
catch (Exception e)
{
LogHelp.Error("ini error! " + e.ToString());
}
}
void context_BeginRequest(object sender, EventArgs e)
{
var httpApplication = sender as HttpApplication;
try
{
if (!core.IsSkip(httpApplication.Context.Request))
{
core.Process(httpApplication.Context);
}
}
catch (Exception ex)
{
LogHelp.Warn("request process error " + httpApplication.Request.RawUrl + " " + ex.ToString());
}
}
#endregion
public void Dispose()
{
}
}
}