forked from YAFNET/YAFNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRewriterHttpModule.cs
More file actions
117 lines (106 loc) · 2.71 KB
/
RewriterHttpModule.cs
File metadata and controls
117 lines (106 loc) · 2.71 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// UrlRewriter - A .NET URL Rewriter module
// Version 2.0
//
// Copyright 2007 Intelligencia
// Copyright 2007 Seth Yates
//
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Resources;
using System.Reflection;
using Intelligencia.UrlRewriter.Configuration;
using Intelligencia.UrlRewriter.Utilities;
namespace Intelligencia.UrlRewriter
{
/// <summary>
/// Rewrites urls based on patterns and conditions specified in the configuration file.
/// This class cannot be inherited.
/// </summary>
public sealed class RewriterHttpModule : IHttpModule
{
/// <summary>
/// Initialises the module.
/// </summary>
/// <param name="context">The application context.</param>
void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(BeginRequest);
}
/// <summary>
/// Disposes of the module.
/// </summary>
void IHttpModule.Dispose()
{
}
/// <summary>
/// Configuration of the rewriter.
/// </summary>
public static RewriterConfiguration Configuration
{
get
{
return RewriterConfiguration.Current;
}
}
/// <summary>
/// Resolves an Application-path relative location
/// </summary>
/// <param name="location">The location</param>
/// <returns>The absolute location.</returns>
public static string ResolveLocation(string location)
{
return _rewriter.ResolveLocation(location);
}
/// <summary>
/// The original query string.
/// </summary>
public static string OriginalQueryString
{
get
{
return _rewriter.OriginalQueryString;
}
set
{
_rewriter.OriginalQueryString = value;
}
}
/// <summary>
/// The final querystring, after rewriting.
/// </summary>
public static string QueryString
{
get
{
return _rewriter.QueryString;
}
set
{
_rewriter.QueryString = value;
}
}
/// <summary>
/// The raw url, before rewriting.
/// </summary>
public static string RawUrl
{
get
{
return _rewriter.RawUrl;
}
set
{
_rewriter.RawUrl = value;
}
}
private void BeginRequest(object sender, EventArgs e)
{
// Add our PoweredBy header
HttpContext.Current.Response.AddHeader(Constants.HeaderXPoweredBy, Configuration.XPoweredBy);
_rewriter.Rewrite();
}
private static RewriterEngine _rewriter = new RewriterEngine(new HttpContextFacade(), RewriterConfiguration.Current);
}
}