Permalink
Browse files

+ #1 Add app setting to enable module only on AppHarbor

  • Loading branch information...
1 parent 6a1fa56 commit 0966fdad37fdce7d84777e19a6a614d7d508cc50 @devatwork committed Mar 7, 2012
View
@@ -8,6 +8,15 @@ This library fixes the following issues for you automagically:
* [http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number](http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number)
* [http://support.appharbor.com/kb/getting-started/information-about-our-load-balancer](http://support.appharbor.com/kb/getting-started/information-about-our-load-balancer)
+## Configuration
+To set up the module properly for both local development and production add the following application setting to your web.config:
+
+ <appSettings>
+ <add key="DOCKED_AT_APPHARBOR" value="false" />
+ </appSettings>
+
+Then on the AppHarbor create an configuration variable with the key DOCKED\_AT\_APPHARBOR with value set to 'true'. See [Managing environments](http://support.appharbor.com/kb/getting-started/managing-environments "Managing environments") pages for more detail.
+
## Contributors
All help is welcome!
@@ -1,6 +1,9 @@
<?xml version="1.0"?>
<configuration>
+ <appSettings>
+ <add key="DOCKED_AT_APPHARBOR" value="false" />
+ </appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
@@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
+using System.Configuration;
using System.Linq.Expressions;
using System.Reflection;
using System.Web;
@@ -19,6 +20,10 @@ public class AppHarborIntegrationModule : IHttpModule
{
#region Constants
/// <summary>
+ /// Defines the name of the module enabled setting.
+ /// </summary>
+ private const string ModuleEnabledSettingKey = "DOCKED_AT_APPHARBOR";
+ /// <summary>
/// AppHarbor uses an loadbalancer which rewrites the REMOTE_ADDR header. The original user's IP addres is stored in a separate header with this name.
/// </summary>
private const string ForwardedUserHostAddressHeaderName = "HTTP_X_FORWARDED_FOR";
@@ -34,6 +39,11 @@ public class AppHarborIntegrationModule : IHttpModule
/// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
public void Init(HttpApplication context)
{
+ // check if the library is enabled or not
+ var isEnabled = ConfigurationManager.AppSettings[ModuleEnabledSettingKey];
+ if (!"true".Equals(isEnabled, StringComparison.OrdinalIgnoreCase))
+ return;
+
// find the server variables collection accessor methods
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
var serverVariablesCollectionType = Type.GetType("System.Web.HttpServerVarsCollection, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
@@ -36,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
</ItemGroup>
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
+ <appSettings>
+ <add key="DOCKED_AT_APPHARBOR" value="false" />
+ </appSettings>
<system.webServer>
<modules>
<remove name="AspNetAppHarborIntegration" />

0 comments on commit 0966fda

Please sign in to comment.