<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
        >

<channel>
        <title>Ugo Lattanzi</title>
        <description>Ugo Lattanzi - </description>
        <link>http://tostring.it</link>
        <lastBuildDate>2016-04-19T07:39:03+00:00</lastBuildDate>
        <pubDate>2016-04-19T07:39:03+00:00</pubDate>
        <ttl>1800</ttl>
        <language>en-US</language>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>


        <item>
                <title>Using Kestrel with ASP.NET 5</title>
                <description>&lt;p&gt;With ASP.NET 5 is possible to host your web applications in different ways; of course you can always host your application using IIS (Internet Information Services) and probably it is the best way if you are running your application on top of a Windows OS, but sometimes could be helpful to run test your application also outside of IIS.&lt;/p&gt;

&lt;p&gt;For all people who don’t know what Kestrel is (but you should have guessed) let me past here the official definition&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Kestrel is a cross-platform web server based on &lt;a href=&quot;https://en.wikipedia.org/wiki/Libuv&quot;&gt;libuv&lt;/a&gt;, a cross-platform asynchronous I/O library. Kestrel is open-source, and you can view the Kestrel source on &lt;a href=&quot;https://github.com/aspnet/KestrelHttpServer&quot;&gt;GitHub&lt;/a&gt;. Kestrel is a great option to at least include support for in your ASP.NET 5 projects so that your project can be easily run by developers on any of the supported platforms. You add support for Kestrel by including “Kestrel” in your project’s dependencies listed in project.json.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that you know what is Kestrel let’s see how to use it.&lt;/p&gt;

&lt;p&gt;First of all, when you create a new project from Visual Studio or Yeoman the project is automatically configured to run using Kestrel, in fact into your &lt;code&gt;project.json&lt;/code&gt;
 you should have something like that&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-001.jpg&quot; alt=&quot;Kestrel-001&quot;&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;My code is based on the RC1 but should be the same also if you are running and older or newer version.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The arrows show you two important things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Kestrel dependency&lt;/li&gt;
&lt;li&gt;Web command&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first one is the normal reference you need if you want to run your web application on Kestrel, the second one is the command to run into your project folder (is the same to run &lt;strong&gt;&lt;em&gt;dnu web&lt;/em&gt;&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;Now you have your application ready (I used Web Application template, see here) you have two ways to run it on Kestrel.&lt;/p&gt;

&lt;p&gt;From command line run &lt;strong&gt;&lt;em&gt;dnu web&lt;/em&gt;&lt;/strong&gt; getting an output like this (maybe you have to &lt;strong&gt;&lt;em&gt;run dnu restore&lt;/em&gt;&lt;/strong&gt; if is the first time with your app)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-002.jpg&quot; alt=&quot;Kestrel-002&quot;&gt;&lt;/p&gt;

&lt;p&gt;or using the play button from Visual Studio &lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-003.jpg&quot; alt=&quot;Kestrel-003&quot;&gt;&lt;/p&gt;

&lt;p&gt;That’s pretty easy but is helpful only you want to test your application locally, right now you are not specifying any domain host and you are exposing your application on to schema http and not https.
That’s not so good in a real world so, let’ start to see how to do more with Kestrel.&lt;/p&gt;

&lt;p&gt;Because we want to run our application on https, first of all we have to buy a certificate. For demo purpose I’ve create one myself (so is not trusted) but is ok for now.
Below the steps to create your own self signed certificate&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-004.jpg&quot; alt=&quot;Kestrel-004&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-005.jpg&quot; alt=&quot;Kestrel-005&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-006.jpg&quot; alt=&quot;Kestrel-006&quot;&gt;&lt;/p&gt;

&lt;p&gt;Now your test certificate is ready, let’s add the Kestrel.Https dependency to our project.
To do that let’s open the &lt;code&gt;project.json&lt;/code&gt; and add &lt;code&gt;Microsoft.AspNet.Server.Kestrel.Https&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now it’s time to configure the certificate into our Startup class like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IApplicationBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                                    &lt;span class=&quot;n&quot;&gt;IHostingEnvironment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;n&quot;&gt;IApplicationEnvironment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;appEnv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;n&quot;&gt;ILoggerFactory&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loggerFactory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;certFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;applicationEnvironment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ApplicationBasePath&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\\democertificate.pfx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;signingCertificate&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;X509Certificate2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;certFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;democertificate.io&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseKestrelHttps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;signingCertificate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//...... your code
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see the code is pretty simple, is enough to create the &lt;code&gt;X509Certificate2&lt;/code&gt; class and call the specific method &lt;code&gt;UseKestrelHttps&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: if you are running the RC1 of &lt;code&gt;Microsoft.AspNet.Server.Kestrel.Https&lt;/code&gt; you have a problem with the schema. That because it’s a bit buggy as you can see here (&lt;a href=&quot;https://github.com/aspnet/KestrelHttpServer/issues/551&quot;&gt;https://github.com/aspnet/KestrelHttpServer/issues/551&lt;/a&gt;). That is fixed with the RC2 (not released yet) but, in the meanwhile, you can use a simple workaround like this&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RequestDelegate&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ChangeContextToHttps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RequestDelegate&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Scheme&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IApplicationBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                                    &lt;span class=&quot;n&quot;&gt;IHostingEnvironment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;n&quot;&gt;IApplicationEnvironment&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;appEnv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;n&quot;&gt;ILoggerFactory&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loggerFactory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;certFile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;applicationEnvironment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ApplicationBasePath&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\\democertificate.pfx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;signingCertificate&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;X509Certificate2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;certFile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;democertificate.io&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ChangeContextToHttps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseKestrelHttps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;signingCertificate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//...... your code
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally we have to specify out custom domain and the https protocol to Kestrel. To do this is enough to add a json file into the root of the project named &lt;code&gt;hosting.json&lt;/code&gt; and put this code into it&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;server&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Microsoft.AspNet.Server.Kestrel&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;server.urls&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;http://localhost:5000;https://localhost:5001&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see you can specify more than one url and, if you have mapped the DNS, you can also replace localhost with your domain (i.e. &lt;a href=&quot;http://tostring.it&quot;&gt;http://tostring.it&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Finally the result&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2016/01/Kestrel-007.jpg&quot; alt=&quot;Kestrel-006&quot;&gt;&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;
</description>
                <link>http://tostring.it/2016/01/12/Using-Kestrel-with-ASPNET-5/</link>
                <guid>http://tostring.it/2016/01/12/Using-Kestrel-with-ASPNET-5</guid>
                <pubDate>2016-01-12T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[aspnet]]></category>
                

        </item>

        <item>
                <title>Log your application errors into Slack</title>
                <description>&lt;p&gt;In our company we use &lt;a href=&quot;https://slack.com/&quot;&gt;Slack&lt;/a&gt; as communication tool (probably since it was released years ago) for about everything.
It is becoming a really important tool because our teams are located throughout Europe with different timezones so, a good communication tools is mandatory.
It means also that the client is always open on our computers, phones and tablets.&lt;/p&gt;

&lt;p&gt;We use it in different ways, to talk one to one, to share funny things, or for projects. Usually for a project we have more than a single private channel, because there are different teams for the project and because we use a channel as alerts application.&lt;/p&gt;

&lt;p&gt;Here is an example about one of our customers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;bmw-ux&lt;/strong&gt; (UX and Art stuff)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;bmw-dev&lt;/strong&gt; (dev, quality assurance, github integration, trello and other tech stuff)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;bmw-alerts&lt;/strong&gt; (alerts by the application)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last channel is the most important one for this post, because we use it to log information when something goes wrong into the application.
Before to see how to use it, let me explain our logging workflow.&lt;/p&gt;

&lt;p&gt;The application is built partially on .NET hosted on Azure and we use Serilog as logging framework. It&amp;#39;s a really good logging framework and it offers several appenders.
We store all logs into ElastichSearch and use Kibana as dashboard to see the log, reports and other cool stuff. The output of our dashbord looks more or less like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/11/SlackLog/Kibana.png&quot; alt=&quot;Kibana-Dashboard&quot;&gt;&lt;/p&gt;

&lt;p&gt;The usage is really simple&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;
&lt;span class=&quot;n&quot;&gt;ILogger&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;LoggerConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ExceptionDataEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MachineNameEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpRequestClientHostIpEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpRequestUrlEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpRequestUrlReferrerEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UserNameEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ThreadIdEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Enrich&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;EnvironmentIdEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Production&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; 
                        &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ApplicationIdEnricher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;applicationName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MinimumLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EmailConnectionInfo&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;EmailSubject&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[BMW {applicationName}] Something went wrong&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;EnableSsl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;smtpConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EnableSsl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;FromEmail&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;smtpConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;From&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;NetworkCredentials&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;NetworkCredential&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;smtpConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;smtpConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Port&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;smtpConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ToEmail&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emailConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SupportEmail&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;MailServer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;smtpConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//https://github.com/serilog/serilog/wiki/Configuration-Basics
&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lc&lt;/span&gt;
                                &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ByExcluding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;le&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;le&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RenderMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;StartsWith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;....myStuff&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                                &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Elasticsearch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ElasticsearchSinkOptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elasticSearchConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;CreateLogger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see in the code above, we use also to send the error via email. For me it&amp;#39;s not the best way to have an important notification.
All people could write you an email and you need a notification everytime you get an email so it&amp;#39;s difficult to enphatize a log message in tons of emails.
For this reason we chose to use a private channel on Slack to log important errors.
I think it&amp;#39;s pretty easy to do that with any logger, but it is for sure using Serilog.&lt;/p&gt;

&lt;p&gt;The first thing to do is to configure Slack integration services:&lt;/p&gt;

&lt;p&gt;Image 1:
&lt;img src=&quot;http://tostring.it/assets/2015/11/SlackLog/001.jpg&quot; alt=&quot;Slack-001&quot;&gt;
Image 2:
&lt;img src=&quot;http://tostring.it/assets/2015/11/SlackLog/002.jpg&quot; alt=&quot;Slack-002&quot;&gt;
Image 3:
&lt;img src=&quot;http://tostring.it/assets/2015/11/SlackLog/003.jpg&quot; alt=&quot;Slack-003&quot;&gt;
Image 4:
&lt;img src=&quot;http://tostring.it/assets/2015/11/SlackLog/004.jpg&quot; alt=&quot;Slack-004&quot;&gt;&lt;/p&gt;

&lt;p&gt;Now save and create your Serilog Slack Sink&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Gaia.Bmw.Logging.Serilog.Sinks&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Net.Http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Enrichers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Serilog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Serilog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Events&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SlackSink&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ILogEventSink&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SlackWebhookUrl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;here the url you copied from the image 2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;applicationId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;environmentType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;


        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Emit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LogEvent&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;applicationId&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;            &lt;span class=&quot;c1&quot;&gt;//read the application identifier from your configuration
&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environmentType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;//read the environment type from your configuration
&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LogEventLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LogEventLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;danger&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LogEventLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;warning&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;good&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;//handlse some scenarios, this probably is not needed in your application
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;
                                &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RenderMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
                                &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;New error occured&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exceptinon&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;
                                &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
                                &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RenderMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;attachments&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;fallback&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[{this.applicationId}] [{this.environmentType}] An error occurred.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exceptinon&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;fields&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
                        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                            &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;
                            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                                &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Project&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                &lt;span class=&quot;k&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;applicationId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                &lt;span class=&quot;n&quot;&gt;@short&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;
                            &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
                            &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;
                            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                                &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Environment&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                &lt;span class=&quot;k&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environmentType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                &lt;span class=&quot;n&quot;&gt;@short&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;
                            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;HttpClient&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HttpClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;PostAsJsonAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SlackWebhookUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now that you have everything ready, it&amp;#39;s time to register the Sink into Serilog so&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;
&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MinimumLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WriteTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SlackSink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;CreateLogger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The output on slack should be like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/11/SlackLog/005.jpg&quot; alt=&quot;Slack-005&quot;&gt;&lt;/p&gt;

&lt;p&gt;If you want to customize the output message take a look &lt;a href=&quot;https://api.slack.com/incoming-webhooks&quot;&gt;here&lt;/a&gt;
Enjoy&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/11/23/Log-your-application-errors-into-Slack/</link>
                <guid>http://tostring.it/2015/11/23/Log-your-application-errors-into-Slack</guid>
                <pubDate>2015-11-23T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[various]]></category>
                

        </item>

        <item>
                <title>What a conference</title>
                <description>&lt;p&gt;Today we announced (&lt;a href=&quot;http://blog.webnextconf.eu/&quot;&gt;here&lt;/a&gt;) by the official channel some important news about the next &lt;strong&gt;Web European Conference&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That will be a really AMAZING conference and we had several news for you and for all the attendees.&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/06/greatscott.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;The previous conference was sold out in 40 minutes for 170 available seats, but now we have more seats so everything should go in the right way for all of you but, if you want to be the first to know about the conference, and to have the possibility to pre-register before the official registration opens, go to our website &lt;a href=&quot;http://webnextconf.eu/&quot; title=&quot;http://webnextconf.eu/&quot;&gt;http://webnextconf.eu/&lt;/a&gt; and subscribe to the mailing list.
First July the registration will be free for all but, few hours early, we&amp;#39;ll send the registration link to all people who subscribe our newsletter.&lt;/p&gt;

&lt;p&gt;As for the previous edition, the conference will be free. That&amp;#39;s really important and it&amp;#39;s the difficult part of the organization.
Is not easy to find the money for speakers, rooms, other stuff and keep the tickets free, for this reason your support is more important than ever.&lt;/p&gt;

&lt;p&gt;During the registration you can choose if you wanna come for free, if you want the lunch (around 10€), the T-Shirt (€10) and if you want to make a donation (as you wish).
We&amp;#39;ll use the donation for the organization, speakers, stickers and other stuff like that.&lt;/p&gt;

&lt;p&gt;The conference will be in Milan, &lt;a href=&quot;http://www.unimib.it/go/102/Home/English&quot;&gt;University of Milano-Bicocca&lt;/a&gt; so, if you think you wanna come, it&amp;#39;s time to book your hotel.
That&amp;#39;s important because there is the Expo fair in Milan, so lot of hotels are fully booked, don&amp;#39;t wait!&lt;/p&gt;

&lt;p&gt;All the information about the location is available on the conference web site &lt;a href=&quot;http://www.webnextconf.eu&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, I&amp;#39;m very happy to announce two important speakers that will be here in Milan
The Great &lt;a href=&quot;https://twitter.com/shanselman&quot;&gt;&lt;strong&gt;Scott Hanselman&lt;/strong&gt;&lt;/a&gt; and the fabulous &lt;a href=&quot;https://twitter.com/despos&quot;&gt;&lt;strong&gt;Dino Esposito&lt;/strong&gt;&lt;/a&gt; who will talk about ASP.NET vNext and &amp;quot;Extending RWD with Lightweight Client-side Device Detection&amp;quot;.&lt;/p&gt;

&lt;p&gt;So far we received almost 50 proposals from 20+ different speakers, but to get even more speeches to choose from, we&amp;#39;ve decided to keep the call for presenters open till the end of June: if you haven&amp;#39;t done it yet and you want have the chance to be in the &amp;quot;speakers room&amp;quot; with Scott, go on our &lt;a href=&quot;https://github.com/Web-European-Conference&quot;&gt;Github account&lt;/a&gt;, fork the &lt;a href=&quot;https://github.com/Web-European-Conference/c4p&quot;&gt;c4p repository&lt;/a&gt;, add your proposal and submit a pull request.&lt;/p&gt;

&lt;p&gt;Is that cool enough?
Yeah! But the surprices are not over, other cool speakers could come, so stay tuned.&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/06/08/What-a-conference/</link>
                <guid>http://tostring.it/2015/06/08/What-a-conference</guid>
                <pubDate>2015-06-08T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[various]]></category>
                

        </item>

        <item>
                <title>An easy way to use StackExchange.Redis</title>
                <description>&lt;p&gt;In the previous post (you can read it &lt;a href=&quot;http://tostring.it/2015/03/05/all-you-need-to-know-about-redis/&quot;&gt;here&lt;/a&gt;) I wrote about how cool is Redis as cache server and I showed the basic steps to run Redis on premise or on Microsoft Azure if you prefer.&lt;/p&gt;

&lt;p&gt;In this post I wanna introduce an small package available on NuGet that complete one of the best library actually available for Redis in a .NET environement.&lt;/p&gt;

&lt;p&gt;The package is &lt;strong&gt;&lt;a href=&quot;https://github.com/imperugo/StackExchange.Redis.Extensions&quot;&gt;StackExchange.Redis.Extensions&lt;/a&gt;&lt;/strong&gt; and, as you can imagine from the name, it offers a set of useful helper.&lt;/p&gt;

&lt;h3&gt;What can we do easily with StackExchange.Redis.Extensions?&lt;/h3&gt;

&lt;p&gt;In the previous post I wrote that you have to serialize and deserialize a class if you wanna store it into Redis because the library stores a byte[] and the value could be sent via network.
Using this library you don&amp;#39;t have to worry about that, it does that for you.
Right now it can use three different serialization libraries :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JSON.Net by NewtonSoft&lt;/strong&gt; &lt;a href=&quot;https://www.nuget.org/packages/StackExchange.Redis.Extensions.Newtonsoft/&quot;&gt;&lt;img src=&quot;http://img.shields.io/nuget/v/StackExchange.Redis.Extensions.Newtonsoft.svg?style=flat&quot; alt=&quot;NuGet Status&quot;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jil&lt;/strong&gt; &lt;a href=&quot;https://www.nuget.org/packages/StackExchange.Redis.Extensions.Jil/&quot;&gt;&lt;img src=&quot;http://img.shields.io/nuget/v/StackExchange.Redis.Extensions.Jil.svg?style=flat&quot; alt=&quot;NuGet Status&quot;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Message Pack CLI&lt;/strong&gt; &lt;a href=&quot;https://www.nuget.org/packages/StackExchange.Redis.Extensions.MsgPack/&quot;&gt;&lt;img src=&quot;http://img.shields.io/nuget/v/StackExchange.Redis.Extensions.MsgPack.svg?style=flat&quot; alt=&quot;NuGet Status&quot;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you need to use another serializazion library you can easily do it by creating an implementation  of &lt;a href=&quot;https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/src/StackExchange.Redis.Extensions.Core/ISerializer.cs&quot;&gt;ISerialize&lt;/a&gt;. Of course in this case a Pull Request is welcome&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the example below I&amp;#39;m going to use JSON.Net but the code is the same for the other librarys, just the Nuget Package changes.&lt;/p&gt;

&lt;p&gt;First step is to install it on our project so:&lt;/p&gt;

&lt;div class=&quot;nuget-badge&quot;&gt;
    &lt;code&gt;PM&amp;gt; Install-Package StackExchange.Redis.Extensions.Newtonsoft&lt;/code&gt;
&lt;/div&gt;

&lt;p&gt;It contains all you need to use Redis, so you don&amp;#39;t have to add StackExchange.Redis because it has the right dependency to it.&lt;/p&gt;

&lt;p&gt;Now that we are ready, it&amp;#39;s enough to create our &lt;code&gt;ICacheHelper&lt;/code&gt; instance&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serializer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;NewtonsoftSerializer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cacheClient&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StackExchangeRedisCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serializer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The constructor of &lt;code&gt;StackExchangeRedisCacheClient&lt;/code&gt;has different overloads offering you the opportunity to specify your custom serializer, database, connection string or, if you have it, your instance of &lt;code&gt;ConnectionMultiplex&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you use the code above is enough the add the following code to your configuration file replacing the right values (host, port, ssl and so on):&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;configSections&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;section&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;redisCacheClient&quot;&lt;/span&gt;
               &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;StackExchange.Redis.Extensions.Core.Configuration.RedisCachingSectionHandler, StackExchange.Redis.Extensions.Core&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/configSections&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;redisCacheClient&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;allowAdmin=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ssl=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;false&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;connectTimeout=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;5000&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;database=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;0&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;hosts&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;add&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;host=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;cachePort=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;6379&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/hosts&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/redisCacheClient&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;If you use a dependency injection framework, probably it&amp;#39;s better to register it as singleton&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From now we have a set of useful methods for the following scenarios:&lt;/p&gt;

&lt;h3&gt;How can I store a complex object into Redis?&lt;/h3&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Firstname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Ugo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Lastname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Lattanzi&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Twitter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;@imperugo&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Blog&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://tostring.it&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;added&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;my cache key&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateTimeOffset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddMinutes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;How can I retrieve an object into Redis?&lt;/h3&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cachedUser&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;my cache key&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;How can I retrieve multiple objects with single roundtrip?&lt;/h3&gt;

&lt;p&gt;That&amp;#39;s one of my favorite features because It&amp;#39;s very helpful in case you have to retrieve several objects in the same time. &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cachedUsers&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;key1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;key2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;key3&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;How can I add multiple objects with single roundtrip?&lt;/h3&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;IList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;();&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Firstname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Ugo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Lastname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Lattanzi&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Twitter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;@imperugo&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Blog&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://tostring.it&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Firstname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Simone&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Lastname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Chiaretta&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Twitter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;@simonech&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Blog&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://codeclimber.net.nz/&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user3&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Firstname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Matteo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Lastname&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Pagani&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Twitter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;@qmatteoq&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Blog&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://qmatteoq.com/&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;added&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Can I search keys into Redis?&lt;/h3&gt;

&lt;p&gt;Yes that&amp;#39;s possible using a specific pattern.
If you want to search all keys that start with &lt;code&gt;myCacheKey&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SearchKeys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myCacheKey*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want to search all keys that contain with &lt;code&gt;myCacheKey&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SearchKeys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*myCacheKey*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want to search all keys that end with &lt;code&gt;myCacheKey&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SearchKeys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*myCacheKey&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Can I use a Redis method directly from ICacheClient without adding another dependency to my class?&lt;/h2&gt;

&lt;p&gt;Of course you can. &lt;code&gt;ICacheClient&lt;/code&gt; exposes a readonly property named &lt;code&gt;Database&lt;/code&gt; that is the implementation of IDatabase by &lt;a href=&quot;https://github.com/StackExchange/StackExchange.Redis&quot;&gt;StackExchange.Redis&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;How can I get server information?&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ICacheClient&lt;/code&gt; has a method &lt;code&gt;GetInfo&lt;/code&gt; and &lt;code&gt;GetInfoAsync&lt;/code&gt; for that:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCacheClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That&amp;#39;s what the library does right now and I&amp;#39;ve to say thanks to &lt;a href=&quot;https://github.com/ziyasal&quot;&gt;ziyasal&lt;/a&gt;, &lt;a href=&quot;https://github.com/ppanyukov&quot;&gt;ppanyukov&lt;/a&gt; and &lt;a href=&quot;https://github.com/rajasekarshanmugam&quot;&gt;rajasekarshanmugam&lt;/a&gt; for the contribution.&lt;/p&gt;

&lt;p&gt;The project is available on Github &lt;strong&gt;&lt;a href=&quot;https://github.com/imperugo/StackExchange.Redis.Extensions&quot;&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/04/23/An-easy-way-to-use-StackExchange-Redis-copy/</link>
                <guid>http://tostring.it/2015/04/23/An-easy-way-to-use-StackExchange-Redis copy</guid>
                <pubDate>2015-04-23T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[various]]></category>
                

        </item>

        <item>
                <title>OWIN Succinctly: free ebook</title>
                <description>&lt;p&gt;I&amp;#39;m very happy to announce that, from today, my first book is available &lt;a href=&quot;http://www.syncfusion.com/resources/techportal/ebooks/&quot;&gt;here&lt;/a&gt; thanks to &lt;a href=&quot;http://www.syncfusion.com/&quot;&gt;&lt;strong&gt;Syncfusion&lt;/strong&gt;&lt;/a&gt; that is a popular company among developers for their great suites of controls.
The ebook is focused on &lt;strong&gt;OWIN&lt;/strong&gt; (Open Web Server Interface for .NET specification) and it&amp;#39;s co-written with my friend &lt;a href=&quot;http://codeclimber.net.nz/&quot;&gt;&lt;strong&gt;Simone Chiaretta&lt;/strong&gt;&lt;/a&gt; who is organizing with me the &lt;a href=&quot;http://webnextconf.eu/&quot;&gt;&lt;strong&gt;2° Web European Conference&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It&amp;#39;s a free ebook and, in 110 pages, it covers the most important things you need to know about OWIN from the basic stuff, like &amp;quot;What is OWIN&amp;quot; and &amp;quot;The Middleware&amp;quot;, to more complex stuff like &amp;quot;Authentication using social networks&amp;quot; like Facebook, Twitter and Google with ASP.NET Identity and ASP.NET MVC.&lt;/p&gt;

&lt;p&gt;Here is the TOC of the book:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OWIN&lt;/li&gt;
&lt;li&gt;Katana&lt;/li&gt;
&lt;li&gt;Using Katana with Other Web Frameworks&lt;/li&gt;
&lt;li&gt;Building Custom Middleware&lt;/li&gt;
&lt;li&gt;Authentication with Katana&lt;/li&gt;
&lt;li&gt;Appendix&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The book is distributed by Syncfusion for free, you just have to register and then you’ll be able to download it both in PDF and Kindle format.
Of course if you have feedbacks or you find something that is not clear, that sounds strange or whatever, please don&amp;#39;t hesistate to &lt;a href=&quot;http://tostring.it/contact/&quot;&gt;&lt;strong&gt;contact me&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/03/owin_Succinctly.png&quot; alt=&quot;Owin Succinctly&quot;&gt;&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/03/16/Owin-Succinctly-free-ebook-for-developers/</link>
                <guid>http://tostring.it/2015/03/16/Owin-Succinctly-free-ebook-for-developers</guid>
                <pubDate>2015-03-16T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[Owin]]></category>
                

        </item>

        <item>
                <title>All you need to know about Redis</title>
                <description>&lt;p&gt;I know, the title is a bit provocative or presumptuous if you prefer, but I think this post could be useful if you wanna approach to Redis as cache server using .NET.
For all the people who don&amp;#39;t know what &lt;a href=&quot;http://redis.io/&quot;&gt;Redis&lt;/a&gt; is, let me quote that definition: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Redis is an open source, BSD licensed, advanced key-value cache and store.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And why is it so cool? This is probably the best answer you can find on internet (source &lt;a href=&quot;http://redis.io/commands/KEYS&quot;&gt;here&lt;/a&gt;):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;Installation&lt;/h1&gt;

&lt;p&gt;Now that is clear why Redis is so cool and why lot of enterprise applications use it, we can see how to use it. First of all we have to download Redis from &lt;a href=&quot;https://raw.github.com/ServiceStack/redis-windows/master/downloads/redis64-latest.zip&quot;&gt;here&lt;/a&gt;, unzip the file and run it locally&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-&quot; data-lang=&quot;&quot;&gt;&amp;gt; redis-server.exe redis.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and the console output should be something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/Redis-Console.png&quot; alt=&quot;RedisConsole&quot;&gt;&lt;/p&gt;

&lt;p&gt;if you want to use Redis on Microsoft Azure, you can do it by creating your instance &lt;a href=&quot;http://portal.azure.com&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/AzureRedis1.png&quot; alt=&quot;Azure1&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/AzureRedis2.png&quot; alt=&quot;Azure2&quot;&gt;&lt;/p&gt;

&lt;p&gt;choose the best plan for you, the location, add your name in the proper field and create it. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;creation could take a while and sometime you can get errors. The reason is that the portal is still in beta but don&amp;#39;t worry, keep trying till you get the redis cache server up &amp;amp; running&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/AzureRedis3.png&quot; alt=&quot;Azure3&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/AzureRedis4.png&quot; alt=&quot;Azure4&quot;&gt;&lt;/p&gt;

&lt;h1&gt;Configuration&lt;/h1&gt;

&lt;p&gt;Here we go, Redis is up &amp;amp; running on your dev machine and/or on Azure if you choose it.
Before to start writing code, it&amp;#39;s important to choose the client library to use. The most used libraries are &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/StackExchange/StackExchange.Redis&quot;&gt;&lt;strong&gt;StackExchange.Redis&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://servicestack.net/redis&quot;&gt;&lt;strong&gt;ServiceStack.Redis&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first one is free and opensource so, if you want to use it, you can do easily. The other one has a AGPL license (from 149$ to 249$).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;if you prefer ServiceStack.Redis you can downgrade to version 3.9.71 which was the last truly free&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article I&amp;#39;m going to use &lt;strong&gt;StackExchange.Redis&lt;/strong&gt; so, let&amp;#39;s start to install it using NuGet&lt;/p&gt;

&lt;div class=&quot;nuget-badge&quot;&gt;
    &lt;code&gt;PM&amp;gt; Install-Package StackExchange.Redis&lt;/code&gt;
&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;There is also a StrongName (StackExchange.Redis.StrongName) package if you need to use it into a signed library.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, it&amp;#39;s time to write some good code:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;imperugo.blog.redis&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Program&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ConnectionMultiplexer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;connectionMultiplexer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IDatabase&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//use locally redis installation
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;connectionString&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{0}:{1}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6379&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;//use azure redis installation
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;azureConnectionString&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{0}:{1},ssl=true,password={2}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;s&quot;&gt;&quot;imperugo-test.redis.cache.windows.net&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;m&quot;&gt;6380&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                    &lt;span class=&quot;s&quot;&gt;&quot;Azure Primary Key&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;connectionMultiplexer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ConnectionMultiplexer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connectionString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;connectionMultiplexer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetDatabase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;For some plans, Redis on azure uses SSL by default. If you prefer a no-secure connection you can enable it via Azure Portal, in this case use 6379 and remove &lt;code&gt;ssl=true&lt;/code&gt; from the connection string&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;Add and Retrieve cache objects&lt;/h1&gt;

&lt;p&gt;StackExchange stores data into Redis sending/retrieving a &lt;code&gt;byte[]&lt;/code&gt; or so, whatever you are storing into Redis must be converted into a &lt;code&gt;byte[]&lt;/code&gt; (string is automatically converted by StackExchange.Redis implementation so we don&amp;#39;t have to do it).&lt;/p&gt;

&lt;p&gt;Let&amp;#39;s start with simple object like a string&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StoreData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;StringSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;GetData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;StringGet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;DeleteData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;KeyDelete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and now we can use this methods&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stored&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StoreData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MyKey&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;my first cache string&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stored&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cachedData&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;GetData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MyKey&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isIt&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cachedData&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;my first cache string&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That&amp;#39;s pretty simple but what about storing complex objects?
As I wrote above, &lt;strong&gt;StackExchange.Redis&lt;/strong&gt; stores only &lt;code&gt;byte[]&lt;/code&gt; data so we have to serialize our complex object and convert it into a &lt;code&gt;byte[]&lt;/code&gt; (there is an implicit conversion in case of string, for this reason we didn&amp;#39;t convert the type &lt;code&gt;string&lt;/code&gt; to &lt;code&gt;byte[]&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;The easiest (and probably the best) way to store complex objects consists to serilize the object into a string before to store the data into Redis.&lt;/p&gt;

&lt;p&gt;Choose your favorite serialized (&lt;a href=&quot;http://www.newtonsoft.com/json&quot;&gt;NewtonSoft&lt;/a&gt; in my case ) and create some helpers like here&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DateTimeOffset&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expiresAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;nc&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serializedObject&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JsonConvert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SerializeObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expiration&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expiresAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Subtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DateTimeOffset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;StringSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serializedObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expiration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serializedObject&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;StringGet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JsonConvert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DeserializeObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serializedObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now we are able to put and retrieve complex objects into Redis, next step is to remove it and check if the value exists&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;KeyDelete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;KeyExists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;if you need async methods, don&amp;#39;t worry, StackExchange.Redis has an async overload for almost every method&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;Resources&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;http://redis.io/commands&quot;&gt;&lt;strong&gt;Redis Commands&lt;/strong&gt;&lt;/a&gt; absolutety the best reference to understand how Redis works and what StackExchage.Redis does under the table.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/StackExchange/StackExchange.Redis&quot;&gt;&lt;strong&gt;StackExchage.Redis&lt;/strong&gt;&lt;/a&gt; documentation is absolutely helpful if you choose this library as your wrapper.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/imperugo/StackExchange.Redis.Extensions/&quot;&gt;&lt;strong&gt;StackExchange.Redis.Extensions&lt;/strong&gt;&lt;/a&gt; is a great library (and I suggest to you it) that wrap the common operation needed with StackExchange.Redis (basically you don&amp;#39;t need to serialize objects or create helpers like I explained above):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add complex objects to Redis;&lt;/li&gt;
&lt;li&gt;Remove an object from Redis;&lt;/li&gt;
&lt;li&gt;Search Keys into Redis;&lt;/li&gt;
&lt;li&gt;Retrieve multiple objects with a single roundtrip;&lt;/li&gt;
&lt;li&gt;Store multiple objects with a single roundtrip;&lt;/li&gt;
&lt;li&gt;Async methods;&lt;/li&gt;
&lt;li&gt;Retrieve Redis Server status;&lt;/li&gt;
&lt;li&gt;Much more;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It uses &lt;strong&gt;Json.Net&lt;/strong&gt; (NewtonSoft), &lt;strong&gt;Jil&lt;/strong&gt; or &lt;strong&gt;Message Pack CLI&lt;/strong&gt; to serialize objects into a &lt;code&gt;byte[]&lt;/code&gt;.
Anyway we&amp;#39;ll see it with the next blog post.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://azure.microsoft.com/blog/2015/02/10/investigating-timeout-exceptions-in-stackexchange-redis-for-azure-redis-cache/&quot;&gt;&lt;strong&gt;Investigating Timeout Exceptions in StackExchange.Redis for Azure Redis Cache&lt;/strong&gt;&lt;/a&gt; great article about possible timeout exception problem with Redis and Azure&lt;/p&gt;

&lt;h1&gt;Dashboard&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Azure Dashboard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/AzureRedis-Dashboard.png&quot; alt=&quot;AzureRedis-Dashboard&quot;&gt;&lt;/p&gt;

&lt;p&gt;It offers basic stats but it&amp;#39;s free when you use Redis with Microsoft Azure&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://redsmin.com/&quot;&gt;&lt;strong&gt;Redsmin&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/Redismin-Dashboard.png&quot; alt=&quot;Redsmin-Dashboard&quot;&gt;&lt;/p&gt;

&lt;p&gt;Probably the most complete dashboard for Redis, offers a set of stats about your Redis servers, supports Azure and has a good prompt allowing you to run Redis command directly on the server without using C# or any other programming language. 
Unfortunately it is not free, &lt;a href=&quot;https://redsmin.com/plans&quot;&gt;here&lt;/a&gt; plans and pricing.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://redisdesktop.com/&quot;&gt;&lt;strong&gt;Redis Desktop Manager&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/RedisDesktop-Dashboard.png&quot; alt=&quot;Redismin-Dashboard&quot;&gt;&lt;/p&gt;

&lt;p&gt;Open Source tool for Windows, Mac and Linux hosted on Github &lt;a href=&quot;https://github.com/uglide/RedisDesktopManager/&quot;&gt;here&lt;/a&gt; (right now it the version 0.7.6) offers to run Redis commands into Redis like Redismin, but unfortunately it doesn&amp;#39;t support Azure yet (there is an issue about that opened &lt;a href=&quot;https://github.com/uglide/RedisDesktopManager/issues/3312&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;Real%20time%20dashboard%20for%20redis&quot;&gt;&lt;strong&gt;Redis Live&lt;/strong&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2015/02/redis-live-Dashboard.png&quot; alt=&quot;redis-live-Dashboard&quot;&gt;&lt;/p&gt;

&lt;p&gt;It&amp;#39;s a real time dashboard for Redis written using Python.&lt;/p&gt;

&lt;h1&gt;Conclusions&lt;/h1&gt;

&lt;p&gt;Redis is absolutely one of the best in memory database available right now. There is a wrapper for every language, it&amp;#39;s got a good documentation and it&amp;#39;s free.
If I were you I&amp;#39;d give it a look!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;staytuned!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/03/05/all-you-need-to-know-about-redis/</link>
                <guid>http://tostring.it/2015/03/05/all-you-need-to-know-about-redis</guid>
                <pubDate>2015-03-05T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[azure]]></category>
                

        </item>

        <item>
                <title>Redirect from http to https yes or no?</title>
                <description>&lt;p&gt;In the previous &lt;a href=&quot;http://tostring.it/2015/02/09/security-headers-using-owin/&quot;&gt;post&lt;/a&gt;, I wrote about HTTP security, particularly about &amp;quot;special&amp;quot; headers. This post is partially related to the previous one, it means I am writing about security in a common scenario for web applications.&lt;/p&gt;

&lt;p&gt;How many times did you add a redirect from an HTTP request to an HTTPS?
I think you did it more than one time and, looking on internet, there are several simple solutions.&lt;/p&gt;

&lt;p&gt;If you are using OWIN it&amp;#39;s enough to create a custom Middleware like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ForceHttpsMiddleware&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OwinMiddleware&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ForceHttpsMiddleware&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OwinMiddleware&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;port&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IOwinContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Uri&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Scheme&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpsUrl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;https://{0}:{1}{2}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Uri&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Uri&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PathAndQuery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Redirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpsUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Nothing complex here, but the question is: &amp;quot;Is it correct to redirect a user from an &lt;strong&gt;unsecure connection&lt;/strong&gt; to a &lt;strong&gt;secure connection&lt;/strong&gt;?&amp;quot;
Basically the answer should be yes, but you must be careful about a particular scenario.&lt;/p&gt;

&lt;p&gt;An unsecure request (HTTP) that includes a cookie and/or SessionId is subject to &lt;a href=&quot;http://en.wikipedia.org/wiki/Session_hijacking&quot;&gt;hijacking attacks&lt;/a&gt; and we don&amp;#39;t want that to happen on our website.
The easiest way to prevent this is to release the cookies only in a secure mode, it means that the cookies are not available from an unsecure request, but only from an HTTPS preventig a &lt;a href=&quot;http://en.wikipedia.org/wiki/Man-in-the-middle_attack&quot;&gt;MITM&lt;/a&gt; (Man in the middle) attack.&lt;/p&gt;

&lt;p&gt;Using Aspnet and Owin you can do it easily&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseCookieAuthentication&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CookieAuthenticationOptions&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;AuthenticationType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Cookies&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CookieSecure&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CookieSecureOption&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Always&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CookieHttpOnly&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here the most important part is &lt;code&gt;CookieSecure&lt;/code&gt; property. It defines that only HTTPS request can access to cookie.
To complete the security scenario, you could add also HTTP Strict Transport Security (HSTS) explained &lt;a href=&quot;http://tostring.it/2015/02/09/security-headers-using-owin/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/02/17/redirect-from-http-to-https-yes-or-no/</link>
                <guid>http://tostring.it/2015/02/17/redirect-from-http-to-https-yes-or-no</guid>
                <pubDate>2015-02-17T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[aspnet]]></category>
                

        </item>

        <item>
                <title>Security Headers using OWIN</title>
                <description>&lt;p&gt;There are several ways to add security to our web application, sometime it could be difficult and requires several hours but, with a good architecture, it could be very easy&lt;/p&gt;

&lt;p&gt;What some developers don&amp;#39;t know is that there are some very useful HTTP Headers available that help your web application to be more secure with the support of the modern browsers.&lt;/p&gt;

&lt;p&gt;The site &lt;a href=&quot;https://www.owasp.org/index.php/List_of_useful_HTTP_headers&quot;&gt;OWASP&lt;/a&gt; has a list of the common security-related HTTP headers that every web application must have.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Strict-Transport-Security&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;also know as (HSTS), is an opt-in security enhancement that it&amp;#39;s specified by a web application to enforce secure (HTTP over SSL/TLS) connections to the server preventing &lt;a href=&quot;http://en.wikipedia.org/wiki/Moxie_Marlinspike#Notable_research&quot;&gt;downgrate attacks&lt;/a&gt; like &lt;a href=&quot;http://en.wikipedia.org/wiki/Man-in-the-middle_attack&quot;&gt;Man-in-the-middle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Browser support: &lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Internet Explorer&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 4&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opera&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 12&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from Mavericks (Mac OS X 10.9)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 4.0.211.0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Options&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;max-age=31536000&lt;/td&gt;
&lt;td&gt;Tells the user-agent to cache the domain in the STS list (which is a list that contains known sites supporting HSTS) for one year&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;max-age=31536000; includeSubDomains&lt;/td&gt;
&lt;td&gt;Tells the user-agent to cache the domain in the STS list for one year and include any sub-domains.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;max-age=0&lt;/td&gt;
&lt;td&gt;Tells the user-agent to remove, or not cache the host in the STS cache&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:  &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-&quot; data-lang=&quot;&quot;&gt;Strict-Transport-Security: max-age=16070400; includeSubDomains
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;X-Frame-Options&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Provides &lt;a href=&quot;https://www.owasp.org/index.php/Clickjacking&quot;&gt;Clickjacking&lt;/a&gt; protection. &lt;/p&gt;

&lt;p&gt;Browser support: &lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;DENY/SAMEORIGIN&lt;/th&gt;
&lt;th&gt;ALLOW-FROM&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Internet Explorer&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from 8.0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from 9.0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 3.6.9 (1.9.2.9)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 18.0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opera&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 10.50&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 4.0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 4.1.249.1042&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Options&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;DENY&lt;/td&gt;
&lt;td&gt;The page cannot be displayed in a frame, regardless of the site attempting to do so&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SAMEORIGIN&lt;/td&gt;
&lt;td&gt;The page can only be displayed in a frame on the same origin as the page itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ALLOW-FROM &lt;a href=&quot;http://www.tostring.it&quot;&gt;http://www.tostring.it&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;The page can only be displayed in a frame on the specified origin.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:  &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-&quot; data-lang=&quot;&quot;&gt;X-Frame-Options: deny
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;X-XSS-Protection&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;This HTTP Header prevents &lt;a href=&quot;https://www.owasp.org/index.php/Cross-site_scripting&quot;&gt;Cross-site scripting&lt;/a&gt; (XSS) enabling the filters available in the most recent browsers.&lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Internet Explorer&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opera&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;not supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;supported&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Options&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Disables the XSS Protections.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Enables the XSS Protections.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1; mode=block&lt;/td&gt;
&lt;td&gt;Enables XSS protections and prevents browser rendering if a potential XSS attack is detected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1; report=&lt;a href=&quot;http://site.com/report&quot;&gt;http://site.com/report&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Available only for Chrome and WebKit allows to report the possible attack to a specific url sending data (using JSON and verb POST)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-&quot; data-lang=&quot;&quot;&gt;X-XSS-Protection: 1; mode=block
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;X-Content-Type-Options&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;This HTTP Header prevents the browsers from MIME-sniffing a response away from the declared content-type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The only option available here is &lt;code&gt;nosniff&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-&quot; data-lang=&quot;&quot;&gt;X-Content-Type-Options: nosniff
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Content-Security-Policy&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;This HTTP Header (aka CSP) is very powerful and it requires a precise tuning because we need to specify all the trusted sources for our pages like Images, Script, Fonts, and so on.&lt;/p&gt;

&lt;p&gt;With the correct configuration the browser doesn&amp;#39;t load a not trusted source preventing execution of dangerous code.&lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Internet Explorer&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;partial support starting from 9.0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 4&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opera&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 15&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;partial support starting from 5.1, total support from 6&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;from version 14&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;table&gt;&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Options&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;default-src&lt;/td&gt;
&lt;td&gt;Specify loading policy for all resources type in case one of the following directive is not defined (fallback)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;script-src&lt;/td&gt;
&lt;td&gt;The script-src directive specifies valid sources for JavaScript&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;object-src&lt;/td&gt;
&lt;td&gt;The object-src directive specifies valid sources for the &lt;code&gt;&amp;lt;object&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;embed&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;applet&amp;gt;&lt;/code&gt; elements.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;style-src&lt;/td&gt;
&lt;td&gt;The style-src directive specifies valid sources for stylesheets.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;img-src&lt;/td&gt;
&lt;td&gt;The style-src directive specifies valid sources for images and favicons.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;media-src&lt;/td&gt;
&lt;td&gt;The media-src directive specifies valid sources for loading media using the &lt;code&gt;&amp;lt;audio&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt; elements.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;frame-src&lt;/td&gt;
&lt;td&gt;The frame-src  directive specifies valid sources for web workers and nested browsing contexts loading using elements such as &lt;code&gt;&amp;lt;frame&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;font-src&lt;/td&gt;
&lt;td&gt;The font-src directive specifies valid sources for fonts loaded using @font-face&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;connect-src&lt;/td&gt;
&lt;td&gt;The connect-src directive defines valid sources for XMLHttpRequest, WebSocket, and EventSource connections&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;form-action&lt;/td&gt;
&lt;td&gt;The form-action  directive specifies valid endpoints for &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; submissions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;plugin-types&lt;/td&gt;
&lt;td&gt;The plugin-types directive specifies the valid plugins that the user agent may invoke.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;reflected-xss&lt;/td&gt;
&lt;td&gt;Instructs a user agent to activate or deactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;report-uri&lt;/td&gt;
&lt;td&gt;The report-uri directive instructs the user agent to report attempts to violate the Content Security Policy (send json using post)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Example: &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-&quot; data-lang=&quot;&quot;&gt;Content-Security-Policy: default-src &#39;self&#39;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now that we know all these header, let&amp;#39;s see how to implement them on our applications.
As usual there are several ways to configure the HTTP Headers, we can do it using WebServer configuration (IIS and Apache support that) or, if we use owin, we can do it using a sample middleware without configuring the webserver.&lt;/p&gt;

&lt;p&gt;The last one is absolutely my favorite implementation because I can switch the webserver without configuring anything (that&amp;#39;s is one of the reason why Owin was created).&lt;/p&gt;

&lt;p&gt;Anyway let&amp;#39;s start to add &lt;strong&gt;SecurityHeadersMiddleware&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;nuget-badge&quot;&gt;
    &lt;code&gt;PM&amp;gt; Install-Package SecurityHeadersMiddleware&lt;/code&gt;
&lt;/div&gt;

&lt;p&gt;and now to configure it is very easy&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;
&lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ContentSecurityPolicyConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//Content-Security-Policy header 
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//Configuring trusted Javascript
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ScriptSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddScheme&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;https&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ScriptSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ScriptSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UnsafeEval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ScriptSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UnsafeInline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ScriptSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cdnjs.cloudflare.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//Configuring trusted connections
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ConnectSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddScheme&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wss&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ConnectSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddScheme&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;https&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ConnectSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//Configuring trusted style
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StyleSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StyleSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UnsafeInline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StyleSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fonts.googleapis.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//Configuring fallback
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DefaultSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//Configuring trusted image source
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ImgSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//Configuring trusted fonts
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FontSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceListKeyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FontSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fonts.googleapis.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FontSrc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddHost&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fonts.gstatic.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ContentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//X-Frame-Options
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AntiClickjackingHeader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;XFrameOption&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Deny&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//X-XSS-Protection
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;XssProtectionHeader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/StefanOssendorf/SecurityHeadersMiddleware&quot;&gt;Here&lt;/a&gt; the github repository.&lt;/p&gt;

&lt;p&gt;Have fun and make your application secure.&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/02/09/security-headers-using-owin/</link>
                <guid>http://tostring.it/2015/02/09/security-headers-using-owin</guid>
                <pubDate>2015-02-09T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[OWIN]]></category>
                

        </item>

        <item>
                <title>Speed up WebAPI on Microsoft Azure</title>
                <description>&lt;p&gt;One of my favorite features of ASP.NET WebAPI is the opportunity to run your code outside Internet Information Service (IIS). I don’t have anything against IIS, in fact my tough matches with this tweet:&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/IIS WebServer.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;But System.Web is really a problem and, in some cases, IIS pipeline is too complicated for a simple REST call.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;we fix one bug and open seven new one (unnamed Microsoft employee on System.Web)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Another important thing I like is cloud computing and Microsoft Aure in this case. In fact, if you want to run your APIs outside IIS and you have to scale on Microsoft Azure, maybe this article could be helpful.&lt;/p&gt;

&lt;p&gt;Azure offers different ways to host your APIs and scale them. The most common solutions are WebSites or Cloud Services.&lt;/p&gt;

&lt;p&gt;Unfortunately we can’t use Azure WebSites because everything there runs on IIS (more info &lt;a href=&quot;http://tostring.it/2014/07/09/nodejs-azure-and-iis/&quot;&gt;here&lt;/a&gt;) so, we have to use the Cloud Services but the question here is &lt;strong&gt;Web Role&lt;/strong&gt; or &lt;strong&gt;Worker Role&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;The main difference among Web Role and Worker Role is that the first one runs on IIS, the domain is configured on the webserver and the port 80 is opened by default; the second one is a process (.exe file to be clear) that runs on a “closed” environment.&lt;/p&gt;

&lt;p&gt;To remain consistent with what is written above, we have to use the Worker Role instead of the Web Role so, let’s start to create it following the steps below:&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/001.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/002.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;Now that the Azure project and Workrole project are ready, It&amp;#39;s important to open the port 80 on the worker role (remember that by default the worker role is a close environment).&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/003.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/004.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;Finally we have the environment ready, It’s time to install few WebAPI packages and write some code.&lt;/p&gt;

&lt;div class=&quot;nuget-badge&quot;&gt;
    &lt;code&gt;PM&amp;gt; Install-Package Microsoft.AspNet.WebApi.OwinSelfHost&lt;/code&gt;
&lt;/div&gt;

&lt;p&gt;Now add OWIN startup class&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/005.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/006.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;and finally configure WebAPI Routing and its OWIN Middleware&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Web.Http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;DemoWorkerRole&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Microsoft.Owin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Owin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;[assembly: OwinStartup(typeof (Startup))]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;DemoWorkerRole&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Startup&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IAppBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HttpConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;// Routing
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Routes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;MapHttpRoute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&quot;Default&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&quot;api/{controller}/{id}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteParameter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Optional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;//Configure WebAPI
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;UseWebApi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and create a demo controller&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Web.Http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;DemoWorkerRole.APIs&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DemoController&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ApiController&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;The parameter value is {0}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Till now nothing special, the app is ready and we have just to configure the worker role that is the WorkerRole.cs file created by Visual Studio.&lt;/p&gt;

&lt;p&gt;What we have to do here, is to read the configuration from Azure (we have to map a custom domain for example) and start the web server.&lt;/p&gt;

&lt;p&gt;To do that, first add the domain on the cloud service configuration following the steps below:&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/007.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align:center&quot;&gt;
  &lt;img src=&quot;http://tostring.it/assets/2015/01/008.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;finally the worker role:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Diagnostics&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Threading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Threading.Tasks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Microsoft.Owin.Hosting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Microsoft.WindowsAzure.ServiceRuntime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;DemoWorkerRole&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;WorkerRole&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RoleEntryPoint&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CancellationTokenSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cancellationTokenSource&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CancellationTokenSource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;readonly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ManualResetEvent&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;runCompleteEvent&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ManualResetEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IDisposable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Trace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;TraceInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WorkerRole is running&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nf&quot;&gt;RunAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cancellationTokenSource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;runCompleteEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;OnStart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Set the maximum number of concurrent connections
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;ServicePointManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DefaultConnectionLimit&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baseUri&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{0}://{1}:{2}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RoleEnvironment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetConfigurationSettingValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;protocol&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;RoleEnvironment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetConfigurationSettingValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;domain&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;RoleEnvironment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetConfigurationSettingValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;port&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;Trace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;TraceInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Starting OWIN at {0}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baseUri&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Information&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WebApp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Startup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StartOptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baseUri&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Trace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;TraceError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;OnStart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;Trace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;TraceInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WorkerRole has been started&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;OnStop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Trace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;TraceInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WorkerRole is stopping&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;cancellationTokenSource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Cancel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;runCompleteEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;WaitOne&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Dispose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;OnStop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;Trace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;TraceInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WorkerRole has stopped&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;RunAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CancellationToken&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cancellationToken&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// TODO: Replace the following with your own logic.
&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cancellationToken&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IsCancellationRequested&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;//Trace.TraceInformation(&quot;Working&quot;);
&lt;/span&gt;                &lt;span class=&quot;n&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;we are almost done, the last step is to configure the right execution context into the &lt;code&gt;ServiceDefinistion.csdef&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;ServiceDefinition&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;imperugo.demo.azure.webapi&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;schemaVersion=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;2014-06.2.4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;WorkerRole&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DemoWorkerRole&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;vmsize=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Small&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;Runtime&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;executionContext=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;elevated&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;Imports&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;Import&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;moduleName=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Diagnostics&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/Imports&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;Endpoints&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;InputEndpoint&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Http&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;protocol=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;port=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;80&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;localPort=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;80&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/Endpoints&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;ConfigurationSettings&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;Setting&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;protocol&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;Setting&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;domain&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;Setting&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;port&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/ConfigurationSettings&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/WorkerRole&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/ServiceDefinition&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here the important part is Runtime node. That part is really important because we are using the HttpListener to read the incoming message from the Web and that requires elevated privileges.&lt;/p&gt;

&lt;p&gt;Now we are up &amp;amp; running using WebAPi hosted on a Cloud Service without using IIS. &lt;/p&gt;

&lt;p&gt;The demo code is available &lt;a href=&quot;http://tostring.it/download/imperugo.demo.azure.webapi.zip&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;
</description>
                <link>http://tostring.it/2015/01/20/speedup-webapi-on-microsoft-azure/</link>
                <guid>http://tostring.it/2015/01/20/speedup-webapi-on-microsoft-azure</guid>
                <pubDate>2015-01-20T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[WebAPI]]></category>
                

        </item>

        <item>
                <title>NodeJs for .NET Developers talk during Codemotion in Milan</title>
                <description>&lt;p&gt;It’s been a while since my last blog post; Unfortunately I’ve been very busy in the latest months for due to some important deliveries for the company I&amp;#39;m working for.&lt;/p&gt;

&lt;p&gt;During the past two days one of my favorite conference, &lt;a href=&quot;http://www.codemotionworld.com/&quot;&gt;Codemotion&lt;/a&gt;, has been in Milan and fortunately I had a talk about &lt;strong&gt;NodeJS for .NET Web Developers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The code used for the demo is available on github &lt;a href=&quot;https://github.com/imperugo/Codemotion---Milan-2014&quot;&gt;here&lt;/a&gt; (the most important demo is the Sample 004) and the slides are available on Slideshare and below:&lt;/p&gt;

&lt;p&gt;&lt;iframe src=&quot;//www.slideshare.net/slideshow/embed_code/42176713&quot; width=&quot;425&quot; height=&quot;355&quot; frameborder=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; style=&quot;border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;&quot; allowfullscreen&gt; &lt;/iframe&gt; &lt;div style=&quot;margin-bottom:5px&quot;&gt; &lt;strong&gt; &lt;a href=&quot;//www.slideshare.net/imperugo/nodejs-for-net-web-developers&quot; title=&quot;Nodejs for .NET web developers&quot; target=&quot;_blank&quot;&gt;Nodejs for .NET web developers&lt;/a&gt; &lt;/strong&gt; from &lt;strong&gt;&lt;a href=&quot;//www.slideshare.net/imperugo&quot; target=&quot;_blank&quot;&gt;Ugo Lattanzi&lt;/a&gt;&lt;/strong&gt; &lt;/div&gt;&lt;/p&gt;

&lt;p&gt;I had a good feeling about the talk, the room was full of people, lot of questions and feedback.
It means there is interest about Node from .NET people.&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/12/02/nodejs-for-net-web-developers-talk-during-codemotion-in-milan/</link>
                <guid>http://tostring.it/2014/12/02/nodejs-for-net-web-developers-talk-during-codemotion-in-milan</guid>
                <pubDate>2014-12-02T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[Events]]></category>
                

        </item>

        <item>
                <title>Introducing Event Starter Kit</title>
                <description>&lt;p style=&quot;text-align:center&quot;&gt;
    &lt;img src=&quot;http://tostring.it/assets/2014/09/We-Want-You.png&quot; style=&quot;text-align:center&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;One month ago we announced (&lt;a href=&quot;http://blog.webnextconf.eu/2014/07/28/announcing-second-web-european-conference/&quot;&gt;here&lt;/a&gt; more info) the next edition of &lt;a href=&quot;http://webnextconf.eu&quot;&gt;Web European Conference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We tried this year to replicate the conference but we got some problems with the venue. This time it seems it&amp;#39;s going better; we don&amp;#39;t have the venue confirmed yet, but we have good feeling about that.&lt;/p&gt;

&lt;p&gt;Anyway, with the conference an important Open Source project was born, we (&lt;a href=&quot;climber.net.nz&quot;&gt;Simone&lt;/a&gt; and I) called it &lt;strong&gt;&lt;a href=&quot;https://github.com/Event-Starter-Kit&quot;&gt;Event Starter Kit&lt;/a&gt;&lt;/strong&gt; (ESK).&lt;/p&gt;

&lt;p&gt;The idea is to create something that helps people to organise a conference with a small effort. In our case, the conference is a tech one, but of course, you can use ESK for all kind of conferences.&lt;/p&gt;

&lt;p&gt;For this reason we are working on several repositories in the same time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Launch page&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blog&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Web site&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mobile app&lt;/strong&gt; (iOS, Android and Windows Phone);&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;of course we didn&amp;#39;t complete everything yet except for the Launch Page and the blog. We planned to complete the project with the Conference, so spring 2015, but of course part of the project must be completed early (like the website).&lt;/p&gt;

&lt;p&gt;For this reason we need help :heart_eyes: &lt;/p&gt;

&lt;p&gt;If you wanna collaborate, contact me or send a PR (see the complete documentation about the project &lt;a href=&quot;https://github.com/imperugo/Event-Starter-Kit&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Website and APIs are written using &lt;a href=&quot;http://nodejs.org&quot;&gt;NodeJs&lt;/a&gt; + &lt;a href=&quot;http://mongodb.org&quot;&gt;Mongo&lt;/a&gt; and, for the mobile apps, we are using &lt;a href=&quot;https://xamarin.com&quot;&gt;Xamarin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Work on ESK is really funny because we are also integrating several external services with our application like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.twitter.com&quot;&gt;Twitter&lt;/a&gt; (for login/registration and sharing)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.facebook.com&quot;&gt;Facebook&lt;/a&gt; (for login/registration and sharing)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://github.com&quot;&gt;Github&lt;/a&gt; (for login because we are nerd);&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://mailchimp.com/&quot;&gt;Mailchimp&lt;/a&gt; (for newsletter);&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.eventbrite.com/&quot;&gt;Eventbrite&lt;/a&gt; (for event registration)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://disqus.com&quot;&gt;Disqus&lt;/a&gt; (for comments)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.slideshare.net/&quot;&gt;Slideshare&lt;/a&gt; (for presentation slides)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://vimeo.com&quot;&gt;Vimeo&lt;/a&gt; (for video sessions)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://paypal.com&quot;&gt;Paypal&lt;/a&gt; (for donations)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why Node and Xamarin?&lt;/p&gt;

&lt;p&gt;I would like to do this using ASP.NET vNext but it seems we have to wait a bit before we can use it on a production environment.
So Node is the perfect solution because we don&amp;#39;t want to impose the choice of server so, if you wanna go on Linux you can, same for Windows (right now we are using &lt;a href=&quot;https://azure.microsoft.com&quot;&gt;Microsoft Azure&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;About Xamarin I think it&amp;#39;s almost clear, same code with 3 different output (iOS, Android and Windows Phone).&lt;/p&gt;

&lt;p&gt;We created a Github organization with all repositories (see it &lt;a href=&quot;https://github.com/Event-Starter-Kit&quot;&gt;here&lt;/a&gt;) and other info about the project are available &lt;a href=&quot;https://github.com/Event-Starter-Kit/docs&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are looking for several roles, starting from Front-end developer (compass, bootstrap, angular and so on) till backend (nodejs, mongodb).&lt;/p&gt;

&lt;p&gt;What are you waiting for? Join us &lt;a href=&quot;https://github.com/Event-Starter-Kit&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/09/02/introducing-event-starter-kit/</link>
                <guid>http://tostring.it/2014/09/02/introducing-event-starter-kit</guid>
                <pubDate>2014-09-02T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[Open Source]]></category>
                

        </item>

        <item>
                <title>NodeJs, Azure and IIS</title>
                <description>&lt;p&gt;Yesterday I spent some time to understand a problem with a &lt;a href=&quot;http://tostring.it/tag/#nodejs&quot;&gt;Node Js&lt;/a&gt; application on &lt;a href=&quot;http://tostring.it/tag/#azure&quot;&gt;Microsoft Azure&lt;/a&gt;.
To be quick, my code was a simple web application built on top of &lt;a href=&quot;http://expressjs.com/&quot;&gt;Express&lt;/a&gt; and the code was something like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;express&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;....&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;configure&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Listening on &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Running locally the code works very well both if you run it on your dev environment or a server. Unfortunately it doesn&amp;#39;t work if you try to run it on Microsoft Azure Website. But Why?&lt;/p&gt;

&lt;p&gt;Adding some log I identified the problem on the port environment, basically process.env.port returns a string instead of a number (to be precise it was &lt;strong&gt;\\.\pipe\e289ed7e-b57b-46bb-8bba-ad8cd1f1529c&lt;/strong&gt;) f
The solution is easy, do not try to convert it to a number but pass it as is to node:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Listening on &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The reason is that Node is not running on its process like on local machine (&lt;code&gt;node app.js&lt;/code&gt; to be clear), but it&amp;#39;s mapped under IIS using &lt;a href=&quot;https://github.com/tjanczuk/iisnode&quot;&gt;IISNode&lt;/a&gt; with a wildcard on an HTTP Handler using &lt;a href=&quot;http://en.wikipedia.org/wiki/Named_pipe&quot;&gt;named pipe&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;system.webServer&amp;gt;&lt;/span&gt;         
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;handlers&amp;gt;&lt;/span&gt;
           &lt;span class=&quot;nt&quot;&gt;&amp;lt;add&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;iisnode&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;app.js&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;verb=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;modules=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;iisnode&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/handlers&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;rewrite&amp;gt;&lt;/span&gt;
           &lt;span class=&quot;nt&quot;&gt;&amp;lt;rules&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;rule&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;StaticContent&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
                     &lt;span class=&quot;nt&quot;&gt;&amp;lt;action&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Rewrite&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;url=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;public{REQUEST_URI}&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;/rule&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;rule&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DynamicContent&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
                     &lt;span class=&quot;nt&quot;&gt;&amp;lt;conditions&amp;gt;&lt;/span&gt;
                          &lt;span class=&quot;nt&quot;&gt;&amp;lt;add&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;input=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{REQUEST_FILENAME}&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;matchType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;IsFile&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;negate=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;True&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/conditions&amp;gt;&lt;/span&gt;
                     &lt;span class=&quot;nt&quot;&gt;&amp;lt;action&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Rewrite&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;url=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;app.js&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;/rule&amp;gt;&lt;/span&gt;
           &lt;span class=&quot;nt&quot;&gt;&amp;lt;/rules&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;/rewrite&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;iisnode&lt;/span&gt; 
      &lt;span class=&quot;na&quot;&gt;debuggingEnabled=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;false&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;logDirectory=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;..\..\LogFiles\nodejs&quot;&lt;/span&gt; 
      &lt;span class=&quot;na&quot;&gt;watchedFiles=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*.js;iisnode.yml;node_modules\*;views\*.jade;views\*.ejb;routes\*.js;views\*.vash&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;/system.webServer&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For confirmation, I wrote to &lt;a href=&quot;http://blog.davidebbo.com/&quot;&gt;David Ebbo&lt;/a&gt; via twitter getting this answer:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/07/NodeJs-IIS.png&quot; alt=&quot;Confirmation&quot;&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately (or not), right now there is no way to run Node outside of IIS on Azure Websites but maybe it&amp;#39;s not a problem, it works :smirk:&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/07/09/nodejs-azure-and-iis/</link>
                <guid>http://tostring.it/2014/07/09/nodejs-azure-and-iis</guid>
                <pubDate>2014-07-09T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[NodeJs]]></category>
                

        </item>

        <item>
                <title>Top "Must Know" Frameworks for .NET web developers</title>
                <description>&lt;p&gt;The idea of this post is born talking with my colleague Antonio about the frameworks a .NET web developer should know (from my point of view of course). 
That&amp;#39;s funny because the list is very long and I asked myself if there is something wrong with my idea of .NET web developer or something else.&lt;/p&gt;

&lt;p&gt;From my point of view (and also for my company) there are two kind of web developers, Back End (server side code) and Front End (javascript, css and HTML).
Unfortunately, in Italy, these figures matches in only one person and the quality of the product obviously falls.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Back End Developer&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;ASP.NET MVC&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://www.asp.net/mvc&quot;&gt;http://www.asp.net/mvc&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;http://aspnetwebstack.codeplex.com/&quot;&gt;http://aspnetwebstack.codeplex.com/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Most of our application runs on top of ASP.NET MVC, so for me it&amp;#39;s really important to know it.
I think it&amp;#39;s a good framework, with a lot of extensibility points, good implementation of the MVC pattern, and we use it in heavy traffic projects without particular problems.
Of course there are few things I don&amp;#39;t like of it (first of all System.Web), but fortunately the vNext will solve these &amp;quot;problems&amp;quot;.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;ASP.NET WEBAPI&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://www.asp.net/web-api&quot;&gt;http://www.asp.net/web-api&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;http://aspnetwebstack.codeplex.com/&quot;&gt;http://aspnetwebstack.codeplex.com/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;ASP.NET Web API is probably the best solution if you know ASP.NET MVC and you don&amp;#39;t have time to learn something else like NancyFx, NodeJs and so on;
The approach is very similar to MVC (Controller + Action). Fortunately it doesn&amp;#39;t have the dependency to System.Web but it&amp;#39;s a Framework totally separate from MVC and sometime you have to duplicate the same code on MVC and Web API because the same interface/class has a different namespace.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;SignalR&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://www.asp.net/signalr&quot;&gt;http://www.asp.net/signalr&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/SignalR/SignalR&quot;&gt;https://github.com/SignalR/SignalR&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;I&amp;#39;m not sure if an another Framework for real time applications exists in .NET world, but surely SignalR it is the most famous and used. Build by the same team of ASP.NET MVC / Web API it offers several clients (iOS and Android with &lt;a href=&quot;http://xamarin.com/&quot;&gt;Xamarin&lt;/a&gt;, Windows 8 and Windows Phone) and finally it supports old browsers (with fallback of course forever-frame, polling and son on).&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;NancyFX&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://nancyfx.org/&quot;&gt;http://nancyfx.org/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/NancyFx/Nancy&quot;&gt;https://github.com/NancyFx/Nancy&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Nancy is a lightweight framework for building HTTP based services on .Net and &lt;a href=&quot;http://mono-project.com/&quot;&gt;Mono&lt;/a&gt; (yes it runs on linux and OSX). The main difference between Nancy and Web API is the routing approach. It uses lambdas to identify relative paths and arguments. Really helpful if you can&amp;#39;t deploy on a Windows Server.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Common Logging&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://netcommon.sourceforge.net/&quot;&gt;http://netcommon.sourceforge.net/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/net-commons/common-logging&quot;&gt;https://github.com/net-commons/common-logging&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;I really like this library. When I need to deploy my code side by side with another application or I have to use a specific logging framework, Common Logging is the perfect solution. It is an abstraction of different logging implementations like &lt;a href=&quot;http://logging.apache.org/log4net/&quot;&gt;Log4net&lt;/a&gt;, &lt;a href=&quot;http://nlog-project.org/&quot;&gt;NLog&lt;/a&gt;, &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ff648951.aspx&quot;&gt;Enterprise library&lt;/a&gt; or whatever you want (you can write your custom bridge).
Like many frameworks in the .NET world, this is a porting of a Java Framework (&lt;a href=&quot;http://commons.apache.org/proper/commons-logging/&quot;&gt;here&lt;/a&gt; more info). Really useful!&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Windsor Container&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://www.castleproject.org/&quot;&gt;http://www.castleproject.org/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/castleproject/Windsor&quot;&gt;https://github.com/castleproject/Windsor&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Probably the first package I add in a new project. I&amp;#39;m really a Dependency Injection addicted and Castle Windsor fits very well with my needs. It&amp;#39;s fast, easy to use, all needed lifecycle and offers lot of extension point (Interceptor, custom lifecycle, factories and so on).&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Automapper&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://automapper.org/&quot;&gt;http://automapper.org/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/AutoMapper/AutoMapper&quot;&gt;https://github.com/AutoMapper/AutoMapper&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;In my Italian blog I &lt;a href=&quot;http://imperugo.tostring.it/archive/2011/10/25/dominio-stai-lontano-dalle-mie-view/&quot;&gt;wrote&lt;/a&gt; about the importance to use a DTO for the views and the responses instead of the Domain Model. Automapper is absolutely the best framework to &amp;quot;copy&amp;quot; data from an entity to a DTO. Easy to use, fast and extensible it&amp;#39;s the second package I install on a new project. A must.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Service Stack&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;https://servicestack.net/&quot;&gt;https://servicestack.net/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/ServiceStack&quot;&gt;https://github.com/ServiceStack&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;An extremely interesting set of Frameworks. It contains a Json serializer, ORM, Redis client and Service Clients. This set of Frameworks matches perfectly with those who are obsessed with performance. The tagline of the Framework is &amp;quot;Simplicity at Speed&amp;quot;. &lt;a href=&quot;http://www.slideshare.net/newmovie/what-istheservicestack-14819151?ref=https://servicestack.net/features&quot;&gt;Here&lt;/a&gt; a good presentation about ServiceStack and performances in .NET application&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Quartz.NET&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://www.quartz-scheduler.net/&quot;&gt;http://www.quartz-scheduler.net/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/quartznet/quartznet&quot;&gt;https://github.com/quartznet/quartznet&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Quartz.NET is a job scheduling system for small or large applications. Like Common Logging, this is a porting from a Java project (&lt;a href=&quot;http://quartz-scheduler.org/&quot;&gt;here&lt;/a&gt; more info). It offers several ways to run a job, from Cron pattern to special calendar, or whatever you like. The nice thing is you can have a storage for your jobs (configurable SQL, Mongo, MySql .....) very useful for scalable applications.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Cache Cow&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/aliostad/CacheCow&quot;&gt;https://github.com/aliostad/CacheCow&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Caching is really important, specially if you application must answer to lot of requests. The best way to keep performance acceptable is to reduce the number of operation, specially if request and response are the same for most of the total requests. Cache Cow is a Framework built by my Twitter friend &lt;a href=&quot;http://www.twitter.com/aliostad&quot;&gt;@aliostad&lt;/a&gt; and it offers an easy way to cache HTTP requests (both from client and server) using WEB API. With few line of code, you can have a good caching in your favorite storage (Redis, Azure Caching, Sql Server and so on).&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Redis&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://redis.io/&quot;&gt;http://redis.io/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/antirez/redis&quot;&gt;https://github.com/antirez/redis&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Redis is an open source caching Framework that offers an advanced Dictionary (key/value) storage. Recently it&amp;#39;s available (as preview) also on Windows Azure (&lt;a href=&quot;http://azure.microsoft.com/blog/2014/06/05/mvc-movie-app-with-azure-redis-cache-in-15-minutes/&quot;&gt;here&lt;/a&gt; a good article explains how to use redis with MVC and Azure). The Performance of this Framework are great: it is very fast, and it also available on distributed infrastructures. If you go in a multi-server application, probably it is the best solution.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;XUnit&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/xunit/xunit&quot;&gt;https://github.com/xunit/xunit&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;This is the most active testing framework for .NET applications. It&amp;#39;s used on lot of the Frameworks mentioned in this post (MS Stack included). It has support for &lt;a href=&quot;http://www.jetbrains.com/resharper/&quot;&gt;Resharper&lt;/a&gt;, &lt;a href=&quot;https://www.devexpress.com/Products/CodeRush/&quot;&gt;CodeRush&lt;/a&gt; Test Runner and &lt;a href=&quot;xamarin.com&quot;&gt;Xamarin&lt;/a&gt; Test Runner.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Autofixture&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/AutoFixture/AutoFixture&quot;&gt;https://github.com/AutoFixture/AutoFixture&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;It&amp;#39;s a framework that helps developers to do Test-Driven Development by automating non-relevant Test Fixture Setup. Really I&amp;#39;m not a fan of TDD but Autofixture contains several features like Automock (helpful if you change frequently the constructor dependencies) and &lt;a href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheorieswithAutoFixture/&quot;&gt;AutoMoqData&lt;/a&gt; that can help all developers.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Sharp Tests Ex&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;http://sharptestex.codeplex.com/&quot;&gt;http://sharptestex.codeplex.com/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;It&amp;#39;s a library born to wrap all testing framework using a fluent syntax. Usually I don&amp;#39;t change often the testing framework but sometime I need to copy part or my code to an existing application that uses NUnit or MS-Test. In this case the only thing to do is change the Testing attribute in the test class.
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Front End Developer&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Sass&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://sass-lang.com/&quot;&gt;http://sass-lang.com/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/sass/sass&quot;&gt;https://github.com/sass/sass&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Sass (Syntactically Awesome Style Sheets) is an extension to CSS. It is CSS as it should have been. Its key features are the ability to use variables, nesting, mixins and loops within your code. This means you can code more quickly and keep your code neat, tidy and easy to maintain. The Sass or SCSS code you write is then compiled in to standard CSS as browsers can&amp;#39;t (yet) understand Sass / SCSS.&lt;/p&gt;

&lt;p&gt;Also take a look at &lt;a href=&quot;http://compass-style.org/&quot;&gt;Compass&lt;/a&gt;, it is a great framework for Sass that contains loads of reusable mixins... no more memorising vendor prefixes and obscure pre-spec CSS3 styles!&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Bootstrap&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://getbootstrap.com/&quot;&gt;http://getbootstrap.com/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/twbs/bootstrap&quot;&gt;https://github.com/twbs/bootstrap&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Created by the guys at Twitter, Bootstrap gives you a massive selection of reusable, robust and attractive styles for your everyday styling needs. It includes a responsive, mobile-first grid system, basic typography styles, styles for common elements such as buttons and form inputs and lots more. Bootstrap is perfect for rapid prototyping but don&amp;#39;t use it for everything otherwise we&amp;#39;ll end up with all sites looking the same!&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Bower&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://bower.io/&quot;&gt;http://bower.io/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Bower is a front-end package management tool, you use it to speed up your dev workflow. It allows you to simply install packages and their dependencies in your project using the command-line. No more Googling for the latest version of jQuery, downloading it, unzipping it, copying it into your project etc... just: &lt;code&gt;$ bower install jquery&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Grunt&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://gruntjs.com/&quot;&gt;http://gruntjs.com/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/gruntjs/&quot;&gt;https://github.com/gruntjs/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Like Bower, Grunt is another dev tool that can be run from the command-line. It is a JavaScript task runner which allows you to automate pretty much anything... minification, unit testing, compiling of Sass, code linting, image compression, launching a node server, creation of documentation, whatever you like. There are many, many Grunt Plugins available which do the most common tasks so it is easy to get started.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Yeoman&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://yeoman.io/&quot;&gt;http://yeoman.io/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/yeoman/yeoman&quot;&gt;https://github.com/yeoman/yeoman&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Yeoman makes using Grunt and Bower even easier. It allows you to scaffold out a project very quickly using a &amp;quot;Generator&amp;quot;. The Generator will create a bare-bones (boilerplate) project architecture, with certain libraries, frameworks, Grunt tasks and Bower dependencies pre-installed. Different Generators are available for different projects. For example if you are starting a new AngularJS app, you would use the Angular Generator and run &lt;code&gt;$ yo angular&lt;/code&gt; and it will set up the architecture, along with basic units tests, install AngularJS and Bootstrap (if you want it).&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;AngularJS&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;https://angularjs.org/&quot;&gt;https://angularjs.org/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/angular/angular.js&quot;&gt;https://github.com/angular/angular.js&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;AngularJS is an open-source MVC JavaScript framework created by Google - it allows you to very quickly extend HTML&amp;#39;s capabilities and create powerful, highly testable web applications. Angular includes two-way declarative data-binding which greatly simplifies complex application development as much of the DOM manipulation is handled automatically by the framework. It is (fairly) well documented and there is an active support community on Stack Overflow.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Karma&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://karma-runner.github.io/&quot;&gt;http://karma-runner.github.io/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/karma-runner/karma/&quot;&gt;https://github.com/karma-runner/karma/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Karma (formerly Testacular) is a framework agnostic test runner. You write your unit tests alongside your application code and you can automatically test your code as you develop. Karma allows you to test your code in real browsers on real devices or in PhantomJS. It is definitely worth watching the introduction video from creator Vojta Jína.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Jasmine&lt;/strong&gt;&lt;/h3&gt;

&lt;h6&gt;Website: &lt;em&gt;&lt;a href=&quot;http://jasmine.github.io/&quot;&gt;http://jasmine.github.io/&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;h6&gt;Source code: &lt;em&gt;&lt;a href=&quot;https://github.com/pivotal/jasmine&quot;&gt;https://github.com/pivotal/jasmine&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;/h6&gt;

&lt;p&gt;Jasmine is a framework for testing JavaScript code. You can use Jasmine to write your unit tests and then run them using Karma. The syntax of Jasmine is very clear and easy to understand, yet powerful.&lt;/p&gt;

&lt;p&gt;If you want to take things further take a look at &lt;a href=&quot;http://facebook.github.io/jest/&quot;&gt;Jest&lt;/a&gt; (by Facebook), it is built on top of Jasmine, and adds some additional levels to Jasmine&amp;#39;s feature-set.&lt;/p&gt;

&lt;p&gt;&lt;br/&gt;&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;It&amp;#39;s an hard life for our developers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thanks to my friend &lt;a href=&quot;https://twitter.com/danielcrisp82&quot;&gt;Daniel Crisp&lt;/a&gt; for the support in this post&lt;/p&gt;
&lt;/blockquote&gt;
</description>
                <link>http://tostring.it/2014/06/30/top-must-know-frameworks-for-net-web-developers/</link>
                <guid>http://tostring.it/2014/06/30/top-must-know-frameworks-for-net-web-developers</guid>
                <pubDate>2014-06-30T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[.NET]]></category>
                

        </item>

        <item>
                <title>Advanced logging with NodeJs</title>
                <description>&lt;p&gt;As I wrote in my previous post &lt;a href=&quot;http://tostring.it/2014/06/03/how-to-configure-a-cluster-with-node-js/&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;http://tostring.it/tag/#nodejs&quot;&gt;Node Js&lt;/a&gt; is becoming a part of my dev life and today I&amp;#39;m gonna write about logging. &lt;/p&gt;

&lt;p&gt;Every good application must have a good logging and NodeJs, as all Frameworks, offers several ways to save information.&lt;/p&gt;

&lt;p&gt;Unfortunately the most used is the classic &lt;code&gt;console.log&lt;/code&gt; method that&amp;#39;s a quick and dirty solution. For all people like me that usually use a robust Framework like &lt;a href=&quot;http://logging.apache.org/log4net/&quot;&gt;Log4Net&lt;/a&gt; or &lt;a href=&quot;http://nlog-project.org/&quot;&gt;NLog&lt;/a&gt;, &lt;code&gt;console.log&lt;/code&gt; doesn&amp;#39;t fit so well with my requirements.&lt;/p&gt;

&lt;p&gt;All these Frameworks offer the opportunity to add more than one Appender to the same logger instance.&lt;/p&gt;

&lt;h2&gt;What&amp;#39;s an appender?&lt;/h2&gt;

&lt;p&gt;Basically It&amp;#39;s a simple way to have more than one output during logging. To be clearer let&amp;#39;s try to think about an application where you want to see your logging in the console, but also in a file or an external service like &lt;a href=&quot;https://raygun.io/&quot;&gt;Raygun&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In my &lt;a href=&quot;https://github.com/imperugo/NodeJs-Sample&quot;&gt;Node sample repository&lt;/a&gt; I created a demo of a simple web page (using &lt;a href=&quot;http://expressjs.com/&quot;&gt;Express&lt;/a&gt;) configuring the web server with the most needed middleware and some logs.&lt;/p&gt;

&lt;p&gt;The result of the log is this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/Node-Consolelog.png&quot; alt=&quot;ConsoleLog&quot;&gt;&lt;/p&gt;

&lt;p&gt;As you can see there are just few lines of log but, when you do something more complex, the number of lines could be a lot and difficult to read.
The problem here is that lot of them are only debug log but some of them could be errors. Using the same color is difficult to understand what is the error and what is not.&lt;/p&gt;

&lt;p&gt;A good solution is to use a logging framework that helps us to log into the console using different colors (red for errors, yellow for warnings and so on) and, in production, switch the log to a file or database.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/flatiron/winston&quot;&gt;Winston&lt;/a&gt; is the equivalent to Log4Net/Log4J/NLog in a NodeJs world. It offers the opportunity to use the Appenders and, in our case, colored console.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;npm install winston --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;now it&amp;#39;s enough to configure it. I&amp;#39;ve logger.js with its configuration&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;winston&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;winston&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;winston&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;emitErrs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;winston&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;transports&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;winston&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;transports&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;info&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;./logs/all-logs.log&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;handleExceptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5242880&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//5MB&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;maxFiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;colorize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}),&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;winston&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;transports&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;debug&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;handleExceptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;colorize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;exitOnError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;exports&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;exports&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stream&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The most important thing is the &lt;code&gt;transports&lt;/code&gt; section where you can specify your Appenders. In this example, I want to log into a file with verbosity level set to &lt;strong&gt;info&lt;/strong&gt;, max 5 files and 5 MB for each and I want a complete full log (verbosity level &lt;strong&gt;debug&lt;/strong&gt;) in the terminal but the different level should use different colors.&lt;/p&gt;

&lt;p&gt;The result is pretty nice:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/Node-Consolelog-colored.png&quot; alt=&quot;ConsoleLog&quot;&gt;&lt;/p&gt;

&lt;p&gt;and &lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/Node-Consolelog-fileappender.png&quot; alt=&quot;ConsoleLog&quot;&gt;&lt;/p&gt;

&lt;p&gt;for the file.&lt;/p&gt;

&lt;p&gt;I think that&amp;#39;s absolutely more readable if you have different colors in the console app. Another cool thing is that you can switch on/off some logging just changing the &lt;code&gt;level&lt;/code&gt; property in the transport configuration.&lt;/p&gt;

&lt;p&gt;In my example, I used Express as MVC framework to render HTML. It offers the opportunity to put you log to have some info about the HTTP Requests.&lt;/p&gt;

&lt;p&gt;So, here is the code:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;../utils/logger&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;express&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Overriding &#39;Express&#39; logger&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;morgan&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)({&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;stream&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stream&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The only importat thing here is the middleware, &lt;code&gt;app.use&lt;/code&gt; where &lt;code&gt;logger.stream comes&lt;/code&gt; from the logger configuration file.&lt;/p&gt;

&lt;p&gt;All my code is available on my Node Sample github repository available &lt;a href=&quot;https://github.com/imperugo/NodeJs-Sample&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Express 4 moved some middleware outside of Express packages, so you have to install it manully (more info &lt;a href=&quot;https://github.com/senchalabs/connect#middleware&quot;&gt;here&lt;/a&gt;). If you are using an older version of Express my code needs some changes because of middleware.&lt;/p&gt;
&lt;/blockquote&gt;
</description>
                <link>http://tostring.it/2014/06/23/advanced-logging-with-nodejs/</link>
                <guid>http://tostring.it/2014/06/23/advanced-logging-with-nodejs</guid>
                <pubDate>2014-06-23T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[NodeJs]]></category>
                

        </item>

        <item>
                <title>How to get notifications from a Windows Azure website</title>
                <description>&lt;p&gt;In my &lt;a href=&quot;http://gaia.is.it/&quot;&gt;company&lt;/a&gt; we switched from &lt;a href=&quot;http://www.visualstudio.com/en-us/products/tfs-overview-vs.aspx&quot;&gt;Team Foundation Server&lt;/a&gt; to &lt;a href=&quot;http://www.github.com&quot;&gt;Github&lt;/a&gt; more than one year ago and we are really happy. In the same period we switched all our server to &lt;a href=&quot;http://azure.microsoft.com/en-us/&quot;&gt;Windows Azure&lt;/a&gt; (&lt;a href=&quot;http://azure.microsoft.com/en-us/services/virtual-machines/&quot;&gt;Virtual Machine&lt;/a&gt;, &lt;a href=&quot;http://azure.microsoft.com/en-us/services/web-sites/&quot;&gt;Web Sites&lt;/a&gt; and &lt;a href=&quot;http://azure.microsoft.com/en-us/services/cloud-services/&quot;&gt;Cloud Services&lt;/a&gt;) and we are equally happy.&lt;/p&gt;

&lt;p&gt;The Azure team works very well and I love to deploy my web sites using Github (there are sevaral providers so, if you don&amp;#39;t use github don&amp;#39;t worry, you&amp;#39;ll find the solution that fits best your needs).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are intersted in how to push your code to Azure website using Git, &lt;a href=&quot;http://azure.microsoft.com/en-us/documentation/articles/web-sites-publish-source-control/&quot;&gt;here&lt;/a&gt; there is a cool post and &lt;a href=&quot;https://github.com/projectkudu/kudu&quot;&gt;here&lt;/a&gt; there&amp;#39;s also an engine used for the deploy based on &lt;a href=&quot;http://tostring.it/tag/#nodejs&quot;&gt;NodeJs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The problem about this approach is that I need to be notified when someone of the team deploy something, especially if the deploy fails.
Unfortunately right now Windows Azure doesn&amp;#39;t send you any notification about a deploy procedure, so you have to remind yourself to go in the administration portal and check the deploy status (see the image below).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/windows-azure-management-portal.png&quot; alt=&quot;Windows Azure Management Portal&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://zapier.com&quot;&gt;Zapier&lt;/a&gt; is the solution to this problem. It allows you to select from many sources, to select an event and to attach an action. 
In my case it means something like &amp;quot;For each failed Azure Website deploy call my phone and read me the report&amp;quot; (You can get a email, sms or whatever you want).&lt;/p&gt;

&lt;p&gt;Here the workflow to configure Zapier:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Select the services&lt;/strong&gt; (&lt;a href=&quot;https://zapier.com/zapbook/&quot;&gt;here&lt;/a&gt; the complete list of the available services)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/Zapier-Trigger.png&quot; alt=&quot;Windows Azure Management Portal&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write your condition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/Zapier-Trigger-Options1.png&quot; alt=&quot;Windows Azure Management Portal&quot;&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compose the message&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/Zapier-Trigger-Options.png&quot; alt=&quot;Windows Azure Management Portal&quot;&gt;&lt;/p&gt;

&lt;p&gt;How f...ing cool is that?&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/06/16/how-to-get-notifications-from-windows-azure-website/</link>
                <guid>http://tostring.it/2014/06/16/how-to-get-notifications-from-windows-azure-website</guid>
                <pubDate>2014-06-16T18:37:42+00:00</pubDate>
                
                        <category><![CDATA[azure]]></category>
                

        </item>

        <item>
                <title>How to configure a cluster with Node Js</title>
                <description>&lt;p&gt;In the last period I&amp;#39;m working a lot with &lt;a href=&quot;http://nodejs.org/&quot;&gt;Node JS&lt;/a&gt; and, for a developer like me who loves C# and .NET, I&amp;#39;m still not sure I really love Node :confused:&lt;/p&gt;

&lt;p&gt;The first impression is positive but I don&amp;#39;t know if it&amp;#39;s just because I&amp;#39;m playing with something new or if I really like the approach; however, for the moment, now I&amp;#39;m happy with it.&lt;/p&gt;

&lt;p&gt;This friday I was explaining my experience with Node to my colleague speaking about the differences between Node and .NET.&lt;/p&gt;

&lt;p&gt;From my point of view the biggest difference among .NET and Node is the async implementation. The first one is &lt;strong&gt;MTA (multi thread application)&lt;/strong&gt; and the second one is &lt;strong&gt;STA (single thread application)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;STA means you can&amp;#39;t open a thread to execute something so your application can manage only one request per time.&lt;/p&gt;

&lt;p&gt;Ok, that&amp;#39;s &lt;strong&gt;absolutely fault&lt;/strong&gt; because Node is smart :smile:&lt;/p&gt;

&lt;p&gt;It&amp;#39;s true that Node is STA but it is async by default, in fact when you do something that goes outside of your application (database query, I/O, web request and so on) Node uses the thread to do other stuff like answer to another request, execute other code in you application and so on.&lt;/p&gt;

&lt;p&gt;That means Node is really really optimised, in fact the performance among .NET and Node JS are very similar and, in several case, Node is faster than .NET.&lt;/p&gt;

&lt;p&gt;But how to increase the number of process with Node so that you can have a good scaling system?&lt;/p&gt;

&lt;p&gt;In the .NET world you can find something similar is ASP.NET (hosted on IIS) and it&amp;#39;s called &amp;quot;&lt;a href=&quot;http://stackoverflow.com/questions/5155684/iis-and-web-garden-configuration&quot;&gt;web garden&lt;/a&gt;&amp;quot;, in Node instead it&amp;#39;s called Cluster.
Basically there are more than one active process and a &amp;quot;manager&amp;quot;.&lt;/p&gt;

&lt;p&gt;In that scenario you can use one process for each core of you computer, so your Node application can scale better with you hardware.&lt;/p&gt;

&lt;p&gt;Basically it&amp;#39;s like running &amp;#39;node app.js&amp;#39; for each core you have, and another process to manage them all.&lt;/p&gt;

&lt;p&gt;First step, install some packages:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;npm install cluster --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The goal of this example is to create one process for each core, so the first thing to do is to read the number of cores installed on your laptop:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;cluster&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isMaster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;os&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cpus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;cluster.isMaster&lt;/code&gt; is necessary to be sure that you are forking it just one time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now if you run the app you should have one process for each core, plus the master&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/NodeCluster.png&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In my case I&amp;#39;ve 8 core, so 9 process because of master.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The next step is to add a webserver, so&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-console&quot; data-lang=&quot;console&quot;&gt;npm install http --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and put your logic for each fork:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;cluster&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;http&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isMaster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;os&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cpus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Create HTTP server.&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;writeHead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This answer comes from the process &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now calling the webserver you can see which process is answering your request:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/06/NodeClusterBrowserAnswer.png&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;Because the code is too simple, probably you&amp;#39;ll get the same &amp;#39;pid&amp;#39; for each request from your browser. The easier way to test it is to lock the thread (yes, I said that) so the &amp;quot;balancer&amp;quot; can switch the request to another process demonstrating the cluster.&lt;/p&gt;

&lt;p&gt;In Node there isn&amp;#39;t something like Thread.Sleep, so the best way to lock a thread is create something that keeps it busy, something like an infinite loop :smirk:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;cluster&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;http&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isMaster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;os&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cpus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Create HTTP server.&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;writeHead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This answer comes from the process &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//that&#39;s just for example&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;

    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want to manage all the processes and to log some events, it could be helpful to track some events for each process and to send a message from the &amp;quot;worker&amp;quot; to the &amp;quot;master&amp;quot; or to check when a process dies.&lt;/p&gt;

&lt;p&gt;To do that it&amp;#39;s necessary to use &lt;code&gt;message&lt;/code&gt; event on the worker, so here&amp;#39;s the code:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;cluster&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;http&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isMaster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Master pid: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numberOfRequests&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;os&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cpus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numCPUs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fork&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nb&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;creating process with id = &#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//getting message&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;message&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;messageHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cmd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cmd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;notifyRequest&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;numberOfRequests&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

      &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Getting message from process : &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;procId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//Getting worker online&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;online&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;online&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Worker pid: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; is online&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//printing the listening port&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;listening&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;online&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Listening on port + &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;//Catching errors&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;exit&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;signal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;signal&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;worker was killed by signal: &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;signal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;worker exited with error code: &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;worker success!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;//Printing number of requests&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;setInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Handled &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;numberOfRequests&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; requests&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Create HTTP server.&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;writeHead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This answer comes from the process &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Message sent from http server&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Notify master about the request&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;notifyRequest&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;procId&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pid&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;


  &lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8080&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I&amp;#39;ve created a repository on github with some demos about Node.js (including this one). You can find the repository &lt;a href=&quot;https://github.com/imperugo/NodeJs-Sample&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/06/03/how-to-configure-a-cluster-with-node-js/</link>
                <guid>http://tostring.it/2014/06/03/how-to-configure-a-cluster-with-node-js</guid>
                <pubDate>2014-06-03T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[NodeJs]]></category>
                

        </item>

        <item>
                <title>Bye bye Wordpress, welcome Github pages</title>
                <description>&lt;p&gt;During the last year I used &lt;a href=&quot;http://wordpress.org/&quot;&gt;Wordpress&lt;/a&gt; for my blog, but I never really liked it. I&amp;#39;m not in love with Wordpress and there are several reason that I try to explain here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maintenance;&lt;/li&gt;
&lt;li&gt;Hosting;&lt;/li&gt;
&lt;li&gt;Updates;&lt;/li&gt;
&lt;li&gt;Backup;&lt;/li&gt;
&lt;li&gt;Test environment;&lt;/li&gt;
&lt;li&gt;Performance;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I&amp;#39;m not saying that Wordpress is not good, I&amp;#39;m saying that it doesn&amp;#39;t match my requirements.
From my point of view (now) a blog engine is something where I can write a post in an easy way.&lt;/p&gt;

&lt;p&gt;Moreover, in the past years I created a blog engine (never completed) based on .NET technologies, its name is &lt;strong&gt;Dexter&lt;/strong&gt; and it&amp;#39;s available on Github &lt;a href=&quot;https://github.com/imperugo/Dexter-Blog-Engine&quot;&gt;here&lt;/a&gt;.
IMHO it is/was better than Wordpress, but with many of the problems mentioned above (my mistake).&lt;/p&gt;

&lt;p&gt;Some weeks ago, &lt;a href=&quot;https://twitter.com/davidebbo&quot;&gt;David Ebbo&lt;/a&gt; synthesised in this &lt;a href=&quot;http://blog.davidebbo.com/2014/01/moving-to-github-pages.html&quot;&gt;post&lt;/a&gt;  my idea of blog engine (&lt;strong&gt;for a nerd of course&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;So, everything has started from that post and I migrated first my &lt;a href=&quot;http://imperugo.tostring.it&quot;&gt;italian blog&lt;/a&gt;, than this blog.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why &lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It offers important advantages; the most important is that it doesn&amp;#39;t require server side code :thumbsup:&lt;/p&gt;

&lt;p&gt;Finally it&amp;#39;s easy to use for a developer. The setup guide is available &lt;a href=&quot;http://jekyllrb.com/docs/installation/&quot;&gt;here&lt;/a&gt; (if you are running Windows I suggest to follow &lt;a href=&quot;http://yizeng.me/2013/05/10/setup-jekyll-on-windows/&quot;&gt;this&lt;/a&gt; guide.)&lt;/p&gt;

&lt;p&gt;Basically it&amp;#39;s built on ruby and it generates static files (simple .html files) with the correct folder structure for pagination, custom pages, permalinks and so on.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/05/Jekyll-folder-structure.png&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;Of course you can&amp;#39;t do some stuff like comments and search, but this is not a problem because &lt;strong&gt;there are several external services that offer for free search and comments (&lt;a href=&quot;https://developers.facebook.com/docs/plugins/comments&quot;&gt;Facebook&lt;/a&gt;, &lt;a href=&quot;https://www.google.com/cse/&quot;&gt;Google&lt;/a&gt; and &lt;a href=&quot;http://disqus.com/&quot;&gt;Disqus&lt;/a&gt; in my case).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Moreover there is another cool advantage of moving your blog to Jekyll, and it&amp;#39;s &lt;a href=&quot;https://pages.github.com/&quot;&gt;Github Pages&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Github offers for all its users the opportunity to have a free hosting for static files creating a repository named yourgithubusername.github.io.&lt;/p&gt;

&lt;p&gt;Once you have created the repository it&amp;#39;s just necessary to push your static files into it and navigate to &lt;a href=&quot;http://yourgithubusername.github.io&quot;&gt;http://yourgithubusername.github.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That&amp;#39;s all!&lt;/p&gt;

&lt;p&gt;Here the problem could be that Jekyll generates static files only after a compilation, so you should compile and then push.
Fortunately there is a solution also for this, Github Pages offers the Jekyll compilation and you don&amp;#39;t have to do that (&lt;a href=&quot;https://help.github.com/articles/using-jekyll-with-pages&quot;&gt;here&lt;/a&gt; a complete guide).&lt;/p&gt;

&lt;p&gt;So, now you have &lt;strong&gt;free hosting&lt;/strong&gt;, amazing &lt;strong&gt;performance&lt;/strong&gt; (your HTML is hosted on Github CDN), everything is managed by a &lt;strong&gt;Git repository&lt;/strong&gt; (so you have the history of all posts (&lt;a href=&quot;https://github.com/imperugo/imperugo.github.io/commits/master/_posts/2014-03-04-how-to-use-CORS-with-ASPNET-WebAPI-2.md&quot;&gt;here&lt;/a&gt; an example)) and you can use your &lt;strong&gt;&lt;a href=&quot;https://help.github.com/categories/20/articles&quot;&gt;custom domain&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To be synthetic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new Markdown file into _posts folders;&lt;/li&gt;
&lt;li&gt;Write the post;&lt;/li&gt;
&lt;li&gt;Push on github repo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Github will compile the static files for you.
Do you wanna know how fast &amp;amp; reliable is Github with Jekyll?
Take a look to this report (remember that my skin is not optimised, lot of requests):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/05/Pingdom-Report.png&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;If I convinced you to use Github, below some advice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To migrate your posts use &lt;a href=&quot;http://import.jekyllrb.com/docs/home/&quot;&gt;this&lt;/a&gt; (it supports several sources like Wordpress, xml, rss and so on);&lt;/li&gt;
&lt;li&gt;If you add the license on github, you can also create/modify/delete posts directly for Github website, so you don&amp;#39;t have to setup your environment. Read &lt;a href=&quot;https://github.com/blog/1327-creating-files-on-github&quot;&gt;this&lt;/a&gt; post;&lt;/li&gt;
&lt;li&gt;Enable some cool Gems like I did &lt;a href=&quot;https://github.com/imperugo/imperugo.github.io/blob/master/_config.yml#L48-L52&quot;&gt;here&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;To render the &lt;strong&gt;emoji&lt;/strong&gt; (the point above is mandatory) remember the &lt;a href=&quot;http://www.emoji-cheat-sheet.com/&quot;&gt;right syntax&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;Be careful with the redirect if you change the url permalink (take a look &lt;a href=&quot;https://help.github.com/articles/redirects-on-github-pages&quot;&gt;here&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;If &lt;a href=&quot;http://www.atom.io&quot;&gt;Atom&lt;/a&gt; is your favorite Markdown editor, install &lt;a href=&quot;https://github.com/arcath/jekyll-atom&quot;&gt;this&lt;/a&gt; package;&lt;/li&gt;
&lt;li&gt;Good free editor for Windows available &lt;a href=&quot;http://www.markdownpad.com/&quot;&gt;here&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;If you wanna create your custom skin, I suggest to start with &lt;strong&gt;Jekyll Bootstrap&lt;/strong&gt; available &lt;a href=&quot;http://jekyllbootstrap.com/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you want something with more features, but you like the speed and the idea of static files, take a look to &lt;a href=&quot;http://octopress.org/&quot;&gt;Octopress&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Enjoy it!&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/05/21/bye-bye-wordpress-welcome-github-pages/</link>
                <guid>http://tostring.it/2014/05/21/bye-bye-wordpress-welcome-github-pages</guid>
                <pubDate>2014-05-21T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[Various]]></category>
                

        </item>

        <item>
                <title>Owin and Katana talk in Paris</title>
                <description>&lt;p&gt;After coming back from my long day in Paris, I finally uploaded the slides and demos of my talk with &lt;a href=&quot;http://codeclimber.net.nz/&quot;&gt;Simone&lt;/a&gt; about &lt;a href=&quot;http://www.owin.org&quot;&gt;Owin&lt;/a&gt; and &lt;a href=&quot;http://katanaproject.codeplex.com/&quot;&gt;Katana&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The code used during the speech is available on Github &lt;a href=&quot;https://github.com/imperugo/ncrafts.owin.katana&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find 5 demos:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;01.OwinIIS&lt;/strong&gt;: Demo of running Katana on IIS Host&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;02.OwinHost&lt;/strong&gt;: Demo of running Katana on OwinHost.exe&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;03.OwinSelfHost&lt;/strong&gt;: Demo of running Katana on self host and with custom error page&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;04.OwinWebAPI&lt;/strong&gt;: Running WebAPI on top of Katana&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;05.OwinMiddleware&lt;/strong&gt;: example of using 3 different middlewares in the Owin pipeline. The 3 middlewares are built using 3 different approaches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As usual the slides are available on Slideshare &lt;a href=&quot;http://www.slideshare.net/imperugo/owin-and-katana&quot;&gt;here&lt;/a&gt;, but you can read them also from this post.&lt;/p&gt;

&lt;iframe src=&quot;http://www.slideshare.net/slideshow/embed_code/34793423&quot; width=&quot;476&quot; height=&quot;400&quot; frameborder=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;Finally I&amp;#39;ve to say thanks to all the people who come to the conference, and a special thanks to &lt;a href=&quot;https://twitter.com/rhwy&quot;&gt;Rui&lt;/a&gt;, &lt;a href=&quot;http://ncrafts.io&quot;&gt;ncrafts&lt;/a&gt; conference was amazing!&lt;/p&gt;

&lt;p&gt;Hope to see you next year!&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/05/16/owin-and-katana-talk-in-paris/</link>
                <guid>http://tostring.it/2014/05/16/owin-and-katana-talk-in-paris</guid>
                <pubDate>2014-05-16T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[Events]]></category>
                

        </item>

        <item>
                <title>Owin, Katana and NCrafts</title>
                <description>&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/04/ncraft.jpg&quot; alt=&quot;ncraf&quot;&gt;&lt;/p&gt;

&lt;p&gt;Recently I&amp;#39;ve been writing and reading lots of articles/tweets about &lt;a href=&quot;http://owin.org/&quot;&gt;OWIN&lt;/a&gt; and its implementation &lt;a href=&quot;https://katanaproject.codeplex.com/&quot;&gt;Katana&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The reason is pretty simple, I&amp;#39;m writing a book with &lt;a href=&quot;http://codeclimber.net.nz/&quot;&gt;Simone Chiaretta&lt;/a&gt; about OWIN for &lt;a href=&quot;http://www.syncfusion.com/&quot;&gt;Syncfusion&lt;/a&gt;.
The book is part of their “&lt;a href=&quot;http://www.syncfusion.com/resources/techportal/ebooks&quot;&gt;Succinctly&lt;/a&gt;” e-book series, so nothing big and complicated, just all you need to know about OWIN/Katana and how to use them in your application.&lt;/p&gt;

&lt;p&gt;For this reason we are really focused on OWIN. In the meantime, our friend &lt;a href=&quot;http://www.rui.fr/&quot;&gt;Rui Carvalho&lt;/a&gt; organized a super cool conference in Paris named &lt;a href=&quot;http://ncrafts.io/&quot;&gt;NCrafts&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is &amp;quot;dangerous&amp;quot; combo because the conference looks really amazing and I&amp;#39;ll speak with Simone about OWIN :-)&lt;/p&gt;

&lt;p&gt;All jokes aside, the conference will be really awesome (Web, Cloud, Data and so on) so, if you don&amp;#39;t have anything planned for the 16 May, hurry up and come to Paris (all the conference info is &lt;a href=&quot;http://ncrafts.io/&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;I&amp;#39;d like to finish the post with a quote from the NCrafts web site:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In other words, we love building software with art, passion and technology and share with everyone.&lt;/p&gt;
&lt;/blockquote&gt;
</description>
                <link>http://tostring.it/2014/04/22/owin-katana-and-ncrafts/</link>
                <guid>http://tostring.it/2014/04/22/owin-katana-and-ncrafts</guid>
                <pubDate>2014-04-22T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[Events]]></category>
                

        </item>

        <item>
                <title>How to use CORS with ASP.NET Web API 2.0</title>
                <description>&lt;p&gt;&lt;span style=&quot;line-height: 1.5em;&quot;&gt;With the latest version of ASP.NET Web API, Microsoft introduced support for cross domain requests, usually called CORS (Cross-Origin Resource Sharing)&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;By default it&amp;#39;s not possible to make HTTP requests using Javascript from a source domain that is different from the called endpoint. For example, this means that it&amp;#39;s not possible to call the URL &lt;a href=&quot;http://mysite.com/api/myrestendpoint&quot;&gt;http://mysite.com/api/myrestendpoint&lt;/a&gt; from a domain &lt;a href=&quot;http://yoursite.com&quot;&gt;http://yoursite.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This limitation has been introduced for security reasons: in fact, without this protection, a malicious javascript code could get info from another site without noticing the user.&lt;/p&gt;

&lt;p&gt;However, even if the reason of this limitation is clear, sometimes we need to call anway something that is not hosted in our site.
The first solution is is to use &lt;a href=&quot;http://en.wikipedia.org/wiki/JSONP&quot;&gt;JSONP&lt;/a&gt;. This approach is easy to use and it&amp;#39;s supported by all browsers; the only problem is that the only HTTP VERB supported is GET, which has a limitation on the lenght of the string that can be passed as query parameter.&lt;/p&gt;

&lt;p&gt;Otherwise, if you need to send lot of information we can&amp;#39;t use this way, so the soulution could be to &amp;quot;proxy&amp;quot; the request locally and forward the data server side or to use CORS.&lt;/p&gt;

&lt;p&gt;Basically CORS communication allow you to overtake the problem by defining some rules that makes the request more &amp;quot;secure&amp;quot;.
Of course the first thing we need is a browser that support CORS: fortunately all the latest browsers support it.
Anyway, we have to consider that, looking at the real world, there are several clients that are still using Internet Explorer 8 which, among other things, doesn&amp;#39;t support CORS.&lt;/p&gt;

&lt;p&gt;The following table (&lt;a href=&quot;source&quot;&gt;http://caniuse.com/cors&lt;/a&gt;) shows which browsers offer CORS support.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/03/cors.jpg&quot; alt=&quot;CORS SUPPORT TABLE&quot;&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;there are several workaround that allows you to use CORS with IE8/9 but there are some limitations with the VERBS (more info &lt;a href=&quot;http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx&quot;&gt;here&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that it&amp;#39;s clear what is CORS, it&amp;#39;s time to configure it using one of the following browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Internet Explorer 10/11&lt;/li&gt;
&lt;li&gt;Chrome (all versions)&lt;/li&gt;
&lt;li&gt;Firefox 3.5+&lt;/li&gt;
&lt;li&gt;Safari 4.x&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we need two different project, one for the client application and another one for the server, both hosted in different domains (in my esamply I used Azure Web Sites, so I&amp;#39;ve &lt;a href=&quot;http://imperdemo.azurewebsite.net&quot;&gt;http://imperdemo.azurewebsite.net&lt;/a&gt; for the server and &lt;a href=&quot;http://imperclient.azurewebsite.net&quot;&gt;http://imperclient.azurewebsite.net&lt;/a&gt; for the client)&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h2&gt;Server Application&lt;/h2&gt;

&lt;p&gt;Once the project has been created, it&amp;#39;s important to enable CORS for our &amp;quot;&lt;strong&gt;trusted&lt;/strong&gt;&amp;quot; domains, in my sample &lt;em&gt;imperclient.azurewebsite.net&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you used the default Visual Studio 2013 template, your Global.asax.cs should look like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;WebApiApplication&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Web&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpApplication&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Application_Start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;AreaRegistration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RegisterAllAreas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;GlobalConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WebApiConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;FilterConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RegisterGlobalFilters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GlobalFilters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Filters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;RouteConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RegisterRoutes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RouteTable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Routes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;BundleConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;RegisterBundles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BundleTable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Bundles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, it&amp;#39;s time to edit the file with the API configuration, &amp;quot;WebApiConfig.cs&amp;quot; into &amp;quot;App_Start&amp;quot;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;N.B.: Before editing the file it&amp;#39;s important to install the right NuGet Package; the default template included with Visual Studio doesn&amp;#39;t have CORS package, so you have to install it manually.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;nuget-badge&quot;&gt;
    &lt;code&gt;PM&amp;gt; Install-Package Microsoft.AspNet.WebApi.Cors&lt;/code&gt;
&lt;/div&gt;

&lt;p&gt;Once all the &amp;quot;ingredients&amp;quot; are ready, it&amp;#39;s time to enable CORS:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Web.Http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;imperugo.webapi.cors.server&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;WebApiConfig&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpConfiguration&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Web API configuration and services
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;EnableCors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;// Web API routes
&lt;/span&gt;            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;MapHttpAttributeRoutes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Routes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;MapHttpRoute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;DefaultApi&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;routeTemplate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;api/{controller}/{id}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;defaults&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteParameter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Optional&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Our API Controller looks like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Collections.Generic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Web.Http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Web.Http.Cors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;imperugo.webapi.cors.server.Controllers&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;EnableCors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;origins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://imperclient.azurewebsites.net&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;methods&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ValuesController&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ApiController&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// GET api/values/5
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;This is my controller response&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The most important part of this code is &lt;strong&gt;EnableCors&lt;/strong&gt; method and the namesake attribute (included the VERBS, Domain and HEADERS)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In case you don&amp;#39;t want to completely &amp;quot;open&amp;quot; the controller to CORS requests, you can use the single attribute in the Action or leave the attribute in the controller and apply the DisableCors attribute to the actions you want to &amp;quot;close&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;Client Application&lt;/h2&gt;

&lt;p&gt;At this time, the server is ready, it&amp;#39;s time to work client side.&lt;/p&gt;

&lt;p&gt;The code we&amp;#39;ll see for the client is just plain Javascript, so you can use a simple .html page without any server side code.&lt;/p&gt;

&lt;p&gt;The HTML Code:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jumbotron&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Test CORS (Cross-origin resource sharing)&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;lead&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;#&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;btn btn-primary btn-large&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;testButton&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Test it now&lt;span class=&quot;ni&quot;&gt;&amp;amp;raquo;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;response&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        NoResponse
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Javascript Code:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;javascript&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;feedbackArea&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;#response&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#39;#testButton&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ajax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;GET&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&#39;http://imperdemo.azurewebsites.net/api/values&#39;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;done&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;feedbackArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jqXHR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;textStatus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;errorThrown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;feedbackArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jqXHR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;responseText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;textStatus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you did everything right, you can to deploy our apps (server and client) to test them.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/03/cors-client.jpg&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;When you click on the &amp;quot;Test It now&amp;quot; button the result should look like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/03/cors-client-show-response.jpg&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;Otherwise if something goes wrong, check the point above.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h2&gt;How does it work&lt;/h2&gt;

&lt;p&gt;CORS is a simple &amp;quot;check&amp;quot; based on HEADERS between the caller and the server.&lt;/p&gt;

&lt;p&gt;The browser (client) adds the current domain into the hader of the request using the key &lt;em&gt;Origin&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The server check that this value matches with the allowed domains specified in the attribute, answering with another HEADER information named &lt;em&gt;Access-Control-Allow-Origin&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If both keys have the same values, you have the data, otherwise you&amp;#39;ll get an error.&lt;/p&gt;

&lt;p&gt;The screenshot below shows the headers:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/03/cors-client-show-response-headers.jpg&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;Here is, instead, the classic error in case the HEADERS doesn&amp;#39;t match:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tostring.it/assets/2014/03/cors-client-show-response-error.jpg&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h2&gt;Conclusions&lt;/h2&gt;

&lt;p&gt;For me that I love to sperate the application using an API layer, CORS is absolutely cool. The onyl downside is that it&amp;#39;s not supported by all the browser. Let&amp;#39;s just hope that hope that all the IE8/9 installations will be replaced soon :-)&lt;/p&gt;

&lt;p&gt;The demo is available &lt;a href=&quot;http://tostring.it/assets/2014/03//sample.zip&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
</description>
                <link>http://tostring.it/2014/03/04/how-to-use-CORS-with-ASPNET-WebAPI-2/</link>
                <guid>http://tostring.it/2014/03/04/how-to-use-CORS-with-ASPNET-WebAPI-2</guid>
                <pubDate>2014-03-04T00:00:00+00:00</pubDate>
                
                        <category><![CDATA[webapi]]></category>
                

        </item>


</channel>
</rss>
