简介
一个简单易扩展的HTTP跳转HTTPS的框架。由配置文件配置规则,然后在HTTPMODULE里截获请求进行规则验证是否跳转HTTPS.
组成:
- web.config,用来配置规则
- HttpsConfiguration,用于读取配置文件
- HttpSecurityModule,用来截获请求触发规则验证
- RequestProcessor,用既有规则验证请求
- PathsMatcher,多路径(URL)匹配器
- PathMatcher,单URL路径匹配器
- PathMatcherFactory,用于创建StartsWith或Exact具体URL路径,可进行更多扩展,如正则表达式匹配。
- SecureRedirection,跳转HTTPS
WEB.CONFIG
<configSections>
<section name="HttpsConfiguration" type="ICStars2_0.Common.ConfigSections.HttpsConfiguration, ICStars2_0.Common, Version=1.0.0.0, Culture=neutral" />
</configSections>
<HttpsConfiguration mode="On">
<paths>
<add path="/Test" />
<add path="/Account" security="Ignore" />
<add path="/Account/Check.aspx" matchType="Exact" />
<add path="/Member" matchType="StartsWith" />
</paths>
</HttpsConfiguration>
mode选项On/Off, 开启或不开启HTTPS跳转
<add path=""/>, 添加一个URL验证规则。 默认security="Secure"并且matchType="StartsWith"
<add path="" security="" matchType="" />,添加一个URL验证规则并设置具体选项。security选项Secure/Ignore,进行HTTPS跳转或忽略当前设置。matchType选项Exact/StartsWith,进行完全匹配或仅匹配开始字串。
HttpsConfiguration
namespace ICStars2_0.Common.ConfigSections
{
public enum Mode
{
On,
Off
}
public enum RequestSecurity
{
Secure,
Ignore
}
public enum PathMatchType
{
Exact,
StartsWith
}
internal sealed class ElementNames
{
internal const string Mode = "mode";
internal const string Paths = "paths";
internal const string MatchType = "matchType";
internal const string Path = "path";
internal const string Security = "security";
}
public class HttpsConfiguration : ConfigurationSection
{
[ConfigurationProperty(Elem