Skip to content

Commit 7c44f9b

Browse files
author
unknown
committed
enable configuration on appSettings
1 parent 54d0143 commit 7c44f9b

4 files changed

Lines changed: 43 additions & 12 deletions

File tree

HttpAuthModule.SampleWeb2/Web.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<configSections>
44
<section name="httpAuthModule" type="System.Configuration.NameValueFileSectionHandler" />
55
</configSections>
6+
<appSettings>
7+
<!-- Override httpAuthModule section value. -->
8+
<add key="HttpAuthModule.Credentials" value="bar:barpass"/>
9+
</appSettings>
610
<httpAuthModule>
711
<!-- If HttpAuthModule has problems, please contact me, https://github.com/nabehiro/HttpAuthModule -->
812
<!--

HttpAuthModule/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static class Config
1010

1111
public static string Get(string key, string nullVal = "")
1212
{
13-
var val = _section[key];
13+
var val = ConfigurationManager.AppSettings["HttpAuthModule." + key] ?? _section[key];
1414
return string.IsNullOrEmpty(val) ? nullVal : val;
1515
}
1616
}

HttpAuthModule/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
3333
// 既定値にすることができます:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.2.1.0")]
36-
[assembly: AssemblyFileVersion("2.2.1.0")]
35+
[assembly: AssemblyVersion("2.2.2.0")]
36+
[assembly: AssemblyFileVersion("2.2.2.0")]

README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Http Auth Module
22
This is Simple Http Authentication HttpModule for ASP.NET (MVC).
33
- Basic Authentication
4-
- Digest Authentication
4+
- Digest Authentication
55
- Restrict IP Address (ip4 or ip6)
66
- Basic or Digest Authentication don't tounch HttpContext.Current.User.
77
- Ignore Path Regex.(specified path skip authentication)
@@ -15,13 +15,18 @@ https://www.nuget.org/packages/HttpAuthModule/
1515

1616
```
1717
PM> Install-Package HttpAuthModule
18-
```
18+
```
1919

2020
After Getting, configure Web.config file.
2121
It's all you do for using HttpAuthModule.
2222

2323
# Configuration
24-
Modify Web.config file.
24+
Modify Web.config file.
25+
26+
Configure on httpAuthModule section or appSettings section.
27+
** appSetting section is prior to httpAuthModule section. **
28+
29+
## configure on httpAuthModule section
2530

2631
```XML
2732
<configuration>
@@ -51,12 +56,12 @@ Modify Web.config file.
5156
- 127.0.0.1 (equals to 127.0.0.1/32)
5257
- 2001:0db8:bd05:01d2:288a:1fc0:0001:0000/16
5358
- ::1 (equals to ::1/128)
54-
59+
5560
e.g) 127.0.0.1;182.249.0.0/16;182.248.112.128/26;::1 -->
5661
<add key="RestrictIPAddresses" value="127.0.0.1;::1"/>
5762
<!-- [optional] If set, specified pattern url request skip http auth and IP Restriction. -->
5863
<add key="IgnorePathRegex" value="^/Home/Ignore$|^/Ignore\.aspx$"/>
59-
<!--
64+
<!--
6065
[optional] If set,specified IPs requests skip http auth Restriction.
6166
value format is same as 'RestrictIPAddresses'
6267
-->
@@ -66,18 +71,41 @@ Modify Web.config file.
6671
<system.webServer>
6772
<modules>
6873
<add type="HttpAuthModule.HttpAuthModule" name="HttpAuthModule"/>
69-
</modules>
74+
</modules>
7075
</system.webServer>
7176
</configuration>
7277
```
7378

79+
## configure on appSettings section
7480

75-
If you apply only http requests for ASP.NET Resource(default.aspx /controller/action, but image.gif, index.html), change "modules -> add" element.
81+
```XML
82+
<configuration>
83+
<appSettings>
84+
<add key="HttpAuthModule.AuthMode" value="Digest" />
85+
<add key="HttpAuthModule.Realm" value="SecureZone"/>
86+
<add key="HttpAuthModule.Credentials" value="hoge:hogepass;foo:foopass;"/>
87+
<add key="HttpAuthModule.DigestNonceValidDuration" value="120"/>
88+
<add key="HttpAuthModule.DigestNonceSalt" value="uht9987bbbSAX" />
89+
<add key="HttpAuthModule.RestrictIPAddresses" value="127.0.0.1;::1"/>
90+
<add key="HttpAuthModule.IgnorePathRegex" value="^/Home/Ignore$|^/Ignore\.aspx$"/>
91+
<add key="HttpAuthModule.RestrictIPAddresses" value="127.0.0.1;::1"/>
92+
</appSettings>
93+
94+
<system.webServer>
95+
<modules>
96+
<add type="HttpAuthModule.HttpAuthModule" name="HttpAuthModule"/>
97+
</modules>
98+
</system.webServer>
99+
</configuration>
100+
```
101+
102+
103+
If you apply only http requests for ASP.NET Resource(default.aspx /controller/action, but image.gif, index.html), change "modules -> add" element.
76104
```XML
77105
<modules>
78106
<!-- add preCondition="managedHandler" -->
79107
<add type="HttpAuthModule.HttpAuthModule" name="HttpAuthModule" preCondition="managedHandler" />
80-
</modules>
108+
</modules>
81109
```
82110

83111
# Disable HttpAuthModule by AppSettings
@@ -98,4 +126,3 @@ if you add HttpAuthModuleEnabled=false to appSettings, HttpAUthModule doesn't ru
98126
HttpAuthModule.dll and Web.config is here, https://github.com/nabehiro/HttpAuthModule/PHPResources
99127

100128
please see detail, http://blogs.gine.jp/taka/archives/2753
101-

0 commit comments

Comments
 (0)