<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by Jens Qvist blog</title> <link>https://world.optimizely.com/blogs/Jens-Qvist-blog/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>Creating a BrowserLanguageCriteria for Visitor groups.</title>            <link>https://world.optimizely.com/blogs/Jens-Qvist-blog/Dates/2011/12/Creating-a-BrowserLanguageCriteria-for-Visitor-groups/</link>            <description>&lt;p&gt;&lt;font size=&quot;1&quot;&gt;This is my first blog post ever, on any site I think! So I’m a bit nervous, but I hope that someone will find it interesting. So here goes!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size=&quot;1&quot;&gt;This morning I decided that I should learn how to create custom criterias for Visitor groups. I started out by reading an &lt;/font&gt;&lt;a href=&quot;http://tedgustaf.com/en/blog/2011/10/create-new-visitor-group-criterion-in-episerver/&quot;&gt;&lt;font size=&quot;1&quot;&gt;article&lt;/font&gt;&lt;/a&gt;&lt;font size=&quot;1&quot;&gt; by Ted Nyberg, to get an idea on how it worked.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size=&quot;1&quot;&gt;But I was short on ideas on what to build. Until I stumbled on &lt;/font&gt;&lt;a title=&quot;http://criteriapack.codeplex.com/&quot; href=&quot;http://criteriapack.codeplex.com/&quot;&gt;&lt;font size=&quot;1&quot;&gt;http://criteriapack.codeplex.com/&lt;/font&gt;&lt;/a&gt;&lt;font size=&quot;1&quot;&gt;, where they had a list on planned criterias. Perfect I thought, and choose to create the BrowserLanguageCriterion. I used BrowserOSCriterion as a template for my own code, and started working. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;/link/f829fb7afc0744e28aa468c74de7f27a.jpg&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;language&quot; border=&quot;0&quot; alt=&quot;language&quot; src=&quot;/link/bce40b64089a4fe2915112720ebd3c7a.jpg&quot; width=&quot;565&quot; height=&quot;432&quot; /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size=&quot;1&quot;&gt;So first I needed a settings class as mentioned in Teds article. I decided that the editor would want to choose a language from a dropdownlist and every culture/language in the browser should be availible. It was easy figuring out how to get all cultures. The problem for me was to get all cultures into an enum, since I started out using EnumSelectionFactory. Which I guess require an enum?&lt;/font&gt;&lt;/p&gt;  &lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;553&quot;&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign=&quot;top&quot; width=&quot;551&quot;&gt;         &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;[DojoWidget(SelectionFactoryType = &lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(EnumSelectionFactory), 
        AdditionalOptions = &lt;span class=&quot;str&quot;&gt;&amp;quot;{ selectOnClick: true }&amp;quot;&lt;/span&gt;)]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; BrowserLanguage { get; set; }&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;
        &lt;style type=&quot;text/css&quot;&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;
&lt;style type=&quot;text/css&quot;&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;font size=&quot;1&quot;&gt;To be honest, I haven’t used Enums much and had to google if there was a possibility to convert a list/array of languages to an enum. Apparently not, according to some forum post. &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size=&quot;1&quot;&gt;My solution was kinda easy once I figured out how to do it. I created my own SelectionFactoryType.&lt;/font&gt;&lt;/p&gt;

&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;1&quot; width=&quot;551&quot;&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign=&quot;top&quot; width=&quot;549&quot;&gt;
        &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font face=&quot;Arial&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; LanguageFactory : ISelectionFactory
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; IEnumerable&amp;lt;SelectListItem&amp;gt; GetSelectListItems(Type property)
    {
        &lt;span class=&quot;rem&quot;&gt;//For each culture availible&lt;/span&gt;
        &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt;(CultureInfo ci &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; CultureInfo.GetCultures(CultureTypes.AllCultures)) {
            &lt;span class=&quot;kwrd&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SelectListItem() { Text = ci.EnglishName, Value = ci.EnglishName };
        }  
    }
}&lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;
        &lt;style type=&quot;text/css&quot;&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;
&lt;style type=&quot;text/css&quot;&gt;











.csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;font size=&quot;1&quot;&gt;and changed my SelectionFactoryType to my newly created one; &lt;/font&gt;

&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;550&quot;&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign=&quot;top&quot; width=&quot;548&quot;&gt;
        &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;[Required]
[DojoWidget(SelectionFactoryType = &lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(LanguageFactory))]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; BrowserLanguage { get; set; }&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;div align=&quot;left&quot;&gt;&lt;font size=&quot;1&quot;&gt;Finished with my settings class, I started working on the criterion class. Basically what I needed was to compare the
    &lt;br /&gt;browserlanguage with the language choosen in the criteria for the visitorgroup.

    &lt;br /&gt;This was done easily by matching the two. &lt;/font&gt;

  &lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;556&quot;&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign=&quot;top&quot; width=&quot;554&quot;&gt;
          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;[VisitorGroupCriterion(
    Category = &lt;span class=&quot;str&quot;&gt;&amp;quot;Technical Criteria&amp;quot;&lt;/span&gt;,
    Description = &lt;span class=&quot;str&quot;&gt;&amp;quot;Match Browser language with specified value&amp;quot;&lt;/span&gt;,
    DisplayName = &lt;span class=&quot;str&quot;&gt;&amp;quot;Browser language&amp;quot;&lt;/span&gt;)]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; BrowserLanguageCriterion : CriterionBase&amp;lt;BrowserLanguageModel&amp;gt;
{
    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; _browserlang;
    &lt;span class=&quot;rem&quot;&gt;//matches the browserlanguage with the criterion set language.&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; IsMatch(System.Security.Principal.IPrincipal principal, &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;System.Web.HttpContextBase httpContext)
    {
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; ((String.IsNullOrEmpty(&lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Model.BrowserLanguage) ? &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt; : &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;        StringMatchHelper.IsMatch(_browserlang, &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Model.BrowserLanguage, &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font face=&quot;Arial&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;        base&lt;/span&gt;.Model.BrowserLanguageMatchType)));             
    }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Subscribe(ICriterionEvents criterionEvents)
    {
        &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Subscribe(criterionEvents);
        criterionEvents.StartRequest += criterionEvents_StartRequest;
    }

    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; criterionEvents_StartRequest(&lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; sender, CriterionEventArgs e)
    {
        &lt;span class=&quot;rem&quot;&gt;//Get the browserlanguage&lt;/span&gt;
        &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; browserLanguage = e.HttpContext.Request.UserLanguages[0];
        Thread.CurrentThread.CurrentCulture = &lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;        System.Globalization.CultureInfo.CreateSpecificCulture(browserLanguage);
        _browserlang = Thread.CurrentThread.CurrentCulture.EnglishName;
    }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Unsubscribe(ICriterionEvents criterionEvents)
    {
        criterionEvents.StartRequest -= criterionEvents_StartRequest;
        &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Unsubscribe(criterionEvents);
    }
}&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;
          &lt;style type=&quot;text/css&quot;&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;

  &lt;br /&gt;&lt;font size=&quot;1&quot;&gt;It was a great experience getting this to work and it made me write my first blog!
    &lt;br /&gt;I’m quite pleased how this day turned out and hope that someone will find my 

    &lt;br /&gt;blogpost interesting!

    &lt;br /&gt;/Jens Qvist Here is the full source;

    &lt;br /&gt;

    &lt;br /&gt;&lt;/font&gt;

  &lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; width=&quot;565&quot;&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign=&quot;top&quot; width=&quot;563&quot;&gt;
          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font face=&quot;Arial&quot;&gt;&lt;font size=&quot;1&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Personalization.VisitorGroups;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Data;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Globalization;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Web.Mvc.VisitorGroups;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.ComponentModel.DataAnnotations;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Mvc;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; EPiServer.Classes
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; BrowserLanguageModel : CriterionModelBase
    {
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; MatchStringType _browserLanguageMatchType;
    
        [DojoWidget(SelectionFactoryType = &lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(EnumSelectionFactory), &lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;             AdditionalOptions = &lt;span class=&quot;str&quot;&gt;&amp;quot;{ selectOnClick: true }&amp;quot;&lt;/span&gt;)]
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; MatchStringType BrowserLanguageMatchType
        {
            get
            {
                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;._browserLanguageMatchType;
            }
            set
            {
                &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;._browserLanguageMatchType = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;;
            }
        }
        [Required]
        [DojoWidget(SelectionFactoryType = &lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(LanguageFactory))]
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; BrowserLanguage { get; set; }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; ICriterionModel Copy()
        {
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.ShallowCopy();
        }
    }

    [VisitorGroupCriterion(
        Category = &lt;span class=&quot;str&quot;&gt;&amp;quot;Technical Criteria&amp;quot;&lt;/span&gt;,
        Description = &lt;span class=&quot;str&quot;&gt;&amp;quot;Match Browser language with specified value&amp;quot;&lt;/span&gt;,
        DisplayName = &lt;span class=&quot;str&quot;&gt;&amp;quot;Browser language&amp;quot;&lt;/span&gt;)]
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; BrowserLanguageCriterion : CriterionBase&amp;lt;BrowserLanguageModel&amp;gt;
    {
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; _browserlang;
        &lt;span class=&quot;rem&quot;&gt;//matches the browserlanguage with the criterion set language.&lt;/span&gt;
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; IsMatch(System.Security.Principal.IPrincipal principal, &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;        System.Web.HttpContextBase httpContext)
        {
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; ((String.IsNullOrEmpty(&lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Model.BrowserLanguage) ? &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt; : &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;            StringMatchHelper.IsMatch(_browserlang, &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Model.BrowserLanguage, &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;            &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Model.BrowserLanguageMatchType)));             
        }
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Subscribe(ICriterionEvents criterionEvents)
        {
            &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Subscribe(criterionEvents);
            criterionEvents.StartRequest += criterionEvents_StartRequest;
        }
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; criterionEvents_StartRequest(&lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; sender, CriterionEventArgs e)
        {
            &lt;span class=&quot;rem&quot;&gt;//Get the browserlanguage&lt;/span&gt;
            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; browserLanguage = e.HttpContext.Request.UserLanguages[0];
            Thread.CurrentThread.CurrentCulture = &lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;

          &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;font size=&quot;1&quot; face=&quot;Arial&quot;&gt;            System.Globalization.CultureInfo.CreateSpecificCulture(browserLanguage);
            _browserlang = Thread.CurrentThread.CurrentCulture.EnglishName;
        }
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Unsubscribe(ICriterionEvents criterionEvents)
        {
            criterionEvents.StartRequest -= criterionEvents_StartRequest;
            &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Unsubscribe(criterionEvents);
        }
    }
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; LanguageFactory : ISelectionFactory
    {
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; IEnumerable&amp;lt;SelectListItem&amp;gt; GetSelectListItems(Type property)
        {
            &lt;span class=&quot;rem&quot;&gt;//For each culture availible&lt;/span&gt;
            &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt;(CultureInfo ci &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; CultureInfo.GetCultures(CultureTypes.AllCultures)) {
                &lt;span class=&quot;kwrd&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SelectListItem() { Text = ci.EnglishName, Value = ci.EnglishName };
            }  
        }
    }
}&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;
          &lt;style type=&quot;text/css&quot;&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;

  &lt;br /&gt;&lt;style type=&quot;text/css&quot;&gt;










table {background: #fff; }
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/div&gt;</description>            <guid>https://world.optimizely.com/blogs/Jens-Qvist-blog/Dates/2011/12/Creating-a-BrowserLanguageCriteria-for-Visitor-groups/</guid>            <pubDate>Mon, 19 Dec 2011 19:11:43 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>