Skip to main content

Server-side AB testing in ASP.NET Core web applications

You've likely heard of Optimizely, or ABTasty, but what if you don't want to shell out money to do your own server-side testing? You know the benefits of server-side testing, it is invaluable. Whether you are a big shop, or small team, you can implement server-side testing today in your ASP.NET Core web application. Today, we will explore how to implement server-side testing in ASP.NET Core web applications with OSWTF.


Graphic showing AB testing (credit to https://www.invespcro.com/blog/12-lessons-from-running-512-ab-tests-in-one-year/)
A/B testing

Disclaimer: I am the author of OSWTF; it is based on work I have previously done working in an ecommerce team. The framework itself does not offer any analytics integration, as that is likely company/project-specific and can easily be added yourself.

*Please be aware before the package gets released as a major release, the framework is subject to breaking changes.



What is OSWTF

OSWTF stands for Open Source Web Testing Framework. The framework is a very simple integration into your web applications to enable server-side testing capabilities. The framework relies solely on filters and options to enable you to set up your own server-side tests.

Let's look at how you can use OSWTF in less than 5 minutes!

Getting your solution set up

  1. Install the NuGet package in your project (Tip: install the package from the Package Manager Console -> "Install-Package OSWTF.Server -Version 0.0.5-alpha")
  2. Modify your Startup.cs class
    using OSWTF.Server.Models;
    
    namespace MyWebProject
    {
        public class Startup
        {
            public void ConfigureServices(IServiceCollection services)
            {
                // Add this line
                services.Configure<TestingOptions>(Configuration.GetSection("OSWTF"));
            }
        }
    }
    
  3. Add an entry into your appsettings.json file
    {
      "Logging": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "AllowedHosts": "*",
      "OSWTF": {
        "Tests": [
          {
            "Name": "MyFirstTest",
            "Split": "50,50",
            "Begin": "2/17/2019",
            "End": "3/17/2019"
          }
        ]
      }
    }
    
  4. Modify your controller action you'd like to AB test
    namespace MyWebProject.Controllers
    {
        public class HomeController : Controller
        {
            [TypeFilter(typeof(ServerSideTestFilter),
                Arguments = new object[] { new string[] { "MyFirstTest" } })]
            public IActionResult Index()
            {
                string variation = ViewBag.ServerSideTests["MyFirstTest"];
    
                // Branch based on variation value
    
                return View();
            }
        }
    }
    

That's it!

Configuring your test

You have a number of options to configure your test with, all of these options are configurable within the appsettings.json file. A sample appsettings.json file with all available options is shown below.
{
  // rest of appsettings.json.. 

  "OSWTF": {
    "Prefix": "oswtf_",
    "Tests": [
      {
        "Name": "MyFirstTest",
        "Split": "50,50",
        "Begin": "2/15/2019",
        "End": "3/15/2019",
        "Exclude": [],
        "TurnOff": false
        "ForceVariation": "1" 
      }
    ]
  }
}

  • Prefix - sets the prefix of the cookies of the server-side tests. This defaults to "oswtf_".
  • Name - the name of the test.
  • Split - how you want to split the traffic to different variations of the test. Each number represents a percentage (totaling to 100%). You can pass any number of comma-separated numbers totaling 100.
  • Begin - the begin date of the server-side test.
  • End - the end date of the server-side test. This is optional - if not provided, the server-side test will run indefinitely.
  • Exclude - an array of string values that match to any Name parameter/s. If provided, a given server-side test will be put in variation 0 (the control) if the user is already in any of the excluded server-side tests.
  • TurnOff - a flag to turn off the test. If not provided (or equal to false) the test is assumed to be active.
  • ForceVariation - used to force a particular variation for users who have not already been put into the server-side test. This value is zero-indexed (starts at 0) and can have a max value of one less than the number of elements in Split.

How does it work

If you want to go into the code, head on over to the Github page. The code you'll want to find is in the OSWTF.Server folder. You can also run a demo from the OSWTF.Demo folder.

For those that want a brief overview.
  1. When a user navigates to a webpage that is decorated with the ServerSideTestFilter, the filter will be executed.
  2. Depending on the test's settings, the user will be put into a variation. If the user is already in a variation, as noted by the presence of a cookie that holds the variation value, the cookie's value will be used instead.
  3. The variation value will be saved in a cookie (this makes server-side testing with a web farm that much easier) and persisted to the ViewBag.
  4. You, the programmer, use the value of the variation and code the server-side test as necessary.

FAQ

While using OSWTF, you should be aware of these facts.
  • The variation value that is available to you in the controller is zero-based. That is, if a given test is splitting traffic 50-50, the variation value can either be 0 or 1.
  • The values that you pass in the TypeFilter in your controllers must match the Name key in your appsettings.json file.
  • You can have a single action process multiple server-side tests, simply by adding more elements to the string array parameter in the ServerSideTestFilter is all you need to do.

Suggestions / Bugs

Please submit a issue.

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. HP has really made it easy for downloading printer drivers. You can reach directly to their site with the link 123.hp.com/ojpro8615. It contains all the suitable and up-to-date drivers for your printer. Just input the name and the model number of your printer in the search box and get the drivers you prefer. To obtain more information connect with our team.

    ReplyDelete
  3. i am ERIC BRUNT by name. Greetings to every one that is reading this testimony. I have been rejected by my wife after three(3) years of marriage just because another Man had a spell on her and she left me and the kid to suffer. one day when i was reading through the web, i saw a post on how this spell caster on this address AKHERETEMPLE@gmail.com have help a woman to get back her husband and i gave him a reply to his address and he told me that a man had a spell on my wife and he told me that he will help me and after 3 days that i will have my wife back. i believed him and today i am glad to let you all know that this spell caster have the power to bring lovers back. because i am now happy with my wife. Thanks for helping me Dr Akhere contact him on email: AKHERETEMPLE@gmail.com
    or
    call/whatsapp:+2349057261346










    i am ERIC BRUNT by name. Greetings to every one that is reading this testimony. I have been rejected by my wife after three(3) years of marriage just because another Man had a spell on her and she left me and the kid to suffer. one day when i was reading through the web, i saw a post on how this spell caster on this address AKHERETEMPLE@gmail.com have help a woman to get back her husband and i gave him a reply to his address and he told me that a man had a spell on my wife and he told me that he will help me and after 3 days that i will have my wife back. i believed him and today i am glad to let you all know that this spell caster have the power to bring lovers back. because i am now happy with my wife. Thanks for helping me Dr Akhere contact him on email: AKHERETEMPLE@gmail.com
    or
    call/whatsapp:+2349057261346










    ReplyDelete








  4. i couldn't believe that i would ever be re-unite with my ex-lover, i was so traumatize staying all alone with no body to stay by me and to be with me, but i was so lucky one certain day to meet this powerful spell caster Dr Akhere,after telling him about my situation he did everything humanly possible to see that my lover come back to me,indeed after casting the spell my ex-lover came back to me less than 48 hours,my ex-lover came back begging me that he will never leave me again,3 months later we got engaged and married,if you are having this same situation just contact Dr Akhere on his email: AKHERETEMPLE@gmail.com thanks very much sir for restoring my ex-lover back to me,his email: AKHERETEMPLE@gmail.com or call/whatsapp:+2349057261346
























    hindi ako makapaniwala na kailanman ay muling makiisa ako sa aking kasintahan, labis akong na-trauma sa pananatiling nag-iisa na walang katawan na manatili sa akin at makakasama ko, ngunit napakasuwerte ako sa isang tiyak na araw upang matugunan ito malakas na spell caster na si Dr Akhere, matapos sabihin sa kanya ang tungkol sa aking sitwasyon ginawa niya ang lahat ng makataong posible upang makita na ang aking kasintahan ay bumalik sa akin, sa katunayan matapos na ihagis ang spell ang aking dating kasintahan ay bumalik sa akin ng mas mababa sa 48 oras, dumating ang dating kasintahan ko. bumalik sa pagmamakaawa sa akin na hindi na niya ako pababayaan, 3 buwan mamaya kami ay nakipag-ugnay at nag-asawa, kung nagkakaroon ka ng parehong sitwasyong ito makipag-ugnay lamang kay Dr Akhere sa kanyang email: AKHERETEMPLE@gmail.com maraming salamat sa sir sa pagpapanumbalik ng aking dating kasintahan bumalik sa akin, ang kanyang email: AKHERETEMPLE@gmail.com o tumawag / whatsapp: +2349057261346

    ReplyDelete
  5. If you are stuck with your online management assignment then in this case you can opt for our Dissertation Writing Services.we provide the best assignment online assignment help.
    We also provide Doctoral Dissertation Help. for students across the globe.
    for more information contact us +16692714848

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Howdy, I am walker. We are offering help for HP Printer. On the off chance that you have any technical glitches, simply contact us. For more information ,visit
    123.hp.com/setup.

    ReplyDelete
  8. i am ERIC BRUNT by name. Greetings to every one that is reading this testimony. I have been rejected by my wife after three(3) years of marriage just because another Man had a spell on her and she left me and the kid to suffer. one day when i was reading through the web, i saw a post on how this spell caster on this address AKHERETEMPLE@gmail.com have help a woman to get back her husband and i gave him a reply to his address and he told me that a man had a spell on my wife and he told me that he will help me and after 3 days that i will have my wife back. F1 2020 Highly Compressed and Cinch Audio Recorder Crack are the best. i believed him and today i am glad to let you all know that this spell caster have the power to bring lovers back. because i am now happy with my wife. Thanks for helping me Dr Akhere contact him on

    ReplyDelete

  9. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.

    Best Artificial Intelligence Company in Dubai


    ReplyDelete
  10. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

    Mobile App Development Company in Dubai

    ReplyDelete
  11. I was diagnosed as HEPATITIS B carrier in 2013 with fibrosis of the
    liver already present. I started on antiviral medications which
    reduced the viral load initially. After a couple of years the virus
    became resistant. I started on HEPATITIS B Herbal treatment from
    ULTIMATE LIFE CLINIC (www.ultimatelifeclinic.com) in March, 2020. Their
    treatment totally reversed the virus. I did another blood test after
    the 6 months long treatment and tested negative to the virus. Amazing
    treatment! This treatment is a breakthrough for all HBV carriers.

    ReplyDelete
  12. I appreciate your cooperation. Right on target I appreciate your help.Thank you so much for sharing all this wonderful info with the how-to's!!!! It is so appreciated!!! You always have good humor in your posts/blogs. So much fun and easy to read!
    Crack Download
    TweakBit Driver Updater Crack
    NewBlueFX Titler Pro Crack
    Cinch Audio Recorder Crack
    Avira Phantom VPN Pro Crack
    Lantern Crack
    Bulk Image Downloader Crack
    Filmora pro Crack

    ReplyDelete
  13. I am very impressed with your post because this post is very beneficial for and provides new knowledge to me. Thanks for sharing.
    Lumion Pro 13.1 Crack

    ReplyDelete
  14. Wow, amazing block structure! How long
    Have you written a blog before? Working on a blog seems easy.
    The overview of your website is pretty good, not to mention what it does.
    In the content!
    Sidifiy Music Converter 2.4.3 Crack

    ReplyDelete



  15. I thought this was a pretty interesting read when it comes to this topic. Thank you
    cinch-audio-recorder-crack

    ReplyDelete
  16. Good herbal medicine for herpes simplex virus..

    It's a miracle product..

    Works Fast in 14 days,

    I am cured from herpes simplex,

    Email Robinsonbuckler11@gmail.com

    ReplyDelete

Post a Comment

Popular posts from this blog

UI redesigns are mostly a waste of time

To preface the article, I primarily work on, and prefer, back-end code. I've been involved in both web and software development for over 4 years now and worked with many front-end and back-end frameworks. New Twitter UI Before all of the UI designers that read this go out and riot and champion against me for saying UI redesigns are a waste of time, let me say that I do value design . I think at the bare minimum, a product or website needs to be usable , and if you possess a good eye and steady hand , you should feel compelled to create something that looks pleasing. David Just stop redesigning the UI all the time . UI redesigns, in my opinion, are a waste of time 95% of the time. Let me explain further. No one cares Come see our fresh new look ! What about our new  material design , come see! I'm sorry, but besides fixing the UI where it impacts the usability of your application, no one is raving about how a redesign makes the application any better.

[Fix] - ASUS PCE-AC68 adapter (no internet)

There seem to be a lot of problems with this adapter, even with such strong performance . Why so many issues? I'm not quite sure, but I needed to find a fix because I kept on losing wifi. The ASUS PCE-AC68 The fix Keeping it short - this is how I fixed the issue: Downloaded the driver for my OS from ASUS's support page -  https://www.asus.com/us/Networking/PCEAC68/HelpDesk_Download/ (in my case it was Windows 10 64-bit). Open Device Manager by holding the Windows key and pressing R, then typing "devmgmt.msc" and hitting Enter. (Don't worry, this isn't a scam . We are simply opening Window's Device Manager through the Microsoft Management Console snap-in .) Navigate to the yellow warning sign sitting under Network adapters and right click it. Select Update driver . Select Browse my computer for driver software  and choose the following path of the OS that you have installed on your computer. (The path for the driver on my computer was C

Logging into a website with Powershell

Powershell is great, and it's lately been my go-to shell while I'm working on Windows. Sorry command prompt I really don't do a lot of work in the shell, but I do like to play with low-level interfaces from time to time. The article is about Linux shells, but goes into good explanation about what a shell is if you don't know. Log into a website Today, I wanted to do something that I have never really tried before and that is logging into a website using Powershell . The concepts behind this are quite simple really, as Powershell has support to send HTTP requests  and that's usually all we need, unless the server has CSRF protections in place (which it should). We are going to attempt  to log in to my favorite website for buying socks, Absolute Socks : Is that a turkey?! In order to do that, we need to have a login. So if you don't already have an account on www.absolutesocks.com , go make one now. Viewing the login request On websites,