Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Feature Toggling for .net
C# ASP Shell
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
nToggle
nToggleDynamicFeatureTest
nToggleTest
nToggleWebTestApp
nToggleWebTests
.gitignore
README
build.bat
build.xml
nToggle.sln

README

Feature Toggling for .net

for more information on the concept of feature toggle see http://martinfowler.com/bliki/FeatureToggle.html

Usage
**** nToggle no longer supports appSettings and is now configured by using it's own configSection
<?xml version="1.0"?>
<configuration>
  <configSections>
    <section
      name="nToggle"
      type="nToggle.Configuration.ToggleConfigurationSection"
      allowLocation="true"
      allowDefinition="Everywhere"
      />
  </configSections>
  
  <nToggle>
    <toggles>
      <add name="TestFeatureOn" value="True"/>
      <add name="TestFeatureOff" value="False"/>
      /*The following toggle will associate a custom IFeatureToggleRepository with the given toggle.  
	    Custom repositories can enable things like A/B testing*/
      <add name="DynamicFeature" repository="nToggleDynamicFeatureTest,nToggleDynamicFeatureTest.TestDynamicRepository" value="True"/>
    </toggles>
  </nToggle>
  <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    <system.web>
        <compilation debug="true"/>
  </system.web>
</configuration>


Remove controls from a web page based on a feature toggle:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ToggledOff.aspx.cs" Inherits="nToggleWebTestApp.ToggledOff" %>

<%@ Register assembly="nToggle" namespace="nToggle" tagprefix="nToggle" %>
<nToggle:WebFeatureToggle ID="FeatureToggle1" EnabledBy="TestFeatureOff" runat="server" >
    <span id="enabledby"> Feature Turned Off</span>
</nToggle:WebFeatureToggle>
<nToggle:WebFeatureToggle ID="FeatureToggle2" RemovedBy="TestFeatureOff"  runat="server" >
    <span id="removedby">Feature Turned Off But Toggle is remove by feature</span>
</nToggle:WebFeatureToggle>
  
 ************ Warning: Asp.net does not populate the  controls collection with inline script tags so the following is NOT valid 
<nToggle:WebFeatureToggle ID="FeatureToggle1" EnabledBy="TestFeatureOff" runat="server" >
    <span id="enabledby"> <%= "Feature Turned Off" %></span>
</nToggle:WebFeatureToggle>


Run code in a Code Behind based on a feature toggle:
protected void Page_Load(object sender, EventArgs e)
        {
            WebFeatureToggle1.RunActionWhenDisabled(CodeToRunIfDisabled);
            WebFeatureToggle1.RunActionWhenEnabled(CodeToRunIfEnabled);
        }
        protected void CodeToRunIfDisabled()
        {
        //your code
        }
        protected void CodeToRunIfEnabled()
        {
        //your code
        }


Something went wrong with that request. Please try again.