Archive for December, 2013

HTML Entities

December 30, 2013 Leave a comment

As of writing, there are various forms of HTML Encoding

  1. The old school version, e.g &lt, >l&
  2. URL Encoding e.g %20
  3. HTML Entities/HTML Number e.g ! (

However the built in libraries in .NET is only capable of handling #1 and #2


For #1 we can either use System.Web.HttpUtility.HtmlDecode or System.Net.WebUtility.HtmlDecode.


For #2, we can use the same libraries as #1 but changing it to URLDecode


However it seems there is no built in libraries to handle #3. The good news is there is an easy way to do it with the current available libraries in .NET


Since all HTML entities are in the format &#[number]; we can use regex to find all of such patterns and replace them with the equivalent character (char)number


Sample code of such a function:

static string HtmlDecode(string s)
           var s2 = WebUtility.HtmlDecode(s);
           foreach(Match M in Regex.Matches(s2, @"\&\#(.*?)\;", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline))
               s2 = Regex.Replace(s2, @"\&\#" + M.Groups[1].Value + @"\;", ""+(char)Convert.ToInt64(M.Groups[1].Value), RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);

           return s2;

Categories: ASP.NET

Installing AppFabric on Windows Server 2012

December 11, 2013 31 comments

Here is the step by step guide to installing AppFabric on Windows Server 2012. If you were to install the executable straightaway, it will fail as there are some dependencies


This is what you will see when you simply install AppFabric on a clean install of Windows Server




To properly setup AppFabric, you need to install the pre-requisites (IIS and ASP.NET 3.5) as well as enable automatic windows update.

IF you want high availability, you will need to install on Enterprise and above versions of windows server

  1. Start up Server Manager and click Add roles and features
  2. Install Web Server (IIS)
  3. Install ASP.NET 3.5. You will need the windows server DVD mounted in the dvd drive or else use the alternative path and point to the sources\sxs folder of the windows server dvd
  4. Enable Windows Update
  5. Download Windows Server AppFabric here
  6. Double click the downloaded executable and click next to everything, you might want to install the whole suite just to play safe
  7. Installation should be successful and you will be greeted with the following screen
  8. If you see the exclamation mark (as shown in the image), goto windows update and do a windows update
  9. Ensure Remote Registry is enabled


Set Remote Registry to Automatic


Search for Caching Administrator, Right click and run as administrator




Get-CacheStatistics [cachename]

Size              : 470016
ItemCount         : 1
RegionCount       : 1
RequestCount      : 37
ReadRequestCount  : 7
WriteRequestCount : 7
MissCount         : 1
IncomingBandwidth : 1671031
OutgoingBandwidth : 1202058


Categories: AppFabric, ASP.NET


December 7, 2013 2 comments

Of recent I’ve been looking at secure cloud storage, where there is end to end encryption of the file and sys admins have no way of viewing the file.


This brought me to Owncloud which as of writing is at 6RC2.


Unfortunately installing Owncloud on a Windows Server IS a pain so I’m detailing the steps here for others that want to follow.


For clarity, the OS that I’m using is Windows Server 2012R2, for the older OS, I believe the only major thing would be the mime type mapping


While the Owncloud installation guide at is relatively decent, it also doesn’t seem to address all the possible issues that occur, so the steps that follow detail EXACTLY what you need to do to get Owncloud to work properly on a windows box


  1. Install Windows Server 2012R2 Standard out of the box
  2. Follow the features that are installed for Web Server
    -You need ODBC logging as SMTP uses ODBC to log
    -No need for ASP.NET installation, Owncloud DOES not need ASP.NET

    image image
    image image
  3. Install IIS Management Tools
  4. Install SMTP Server
  5. Run services.msc and set “Simple Mail Transfer Protocol” Startup type to Automatic.
  6. Start the SMTP Service
  7. Restrict access to the SMTP Service
  8. Disable public access to the SMTP Service from windows firewall
  9. Run IIS Manager and it will prompt if you want to install WebPI, click Yes to install it
  10. Once Web PI is installed, run it and choose and install PHP
  11. Now goto and download the latest community build of MySQL. Run the installation leaving everything to default if you are lazy
  12. Just to play safe, goto Windows Firewall again and ensure that there is no public access to MySQL
  13. Now go and edit C:\Program Files (x86)\PHP\v5.5\php.ini
  14. Change/add the following values inside php.ini
    max_execution_time = 400
    memory_limit = 1G ;1G of memory usage for php
    upload_max_filesize = 1G ;up to 1GB file can be uploaded
  15. Add in the OpenSSL Config
    Found at C:\Program Files (x86)\PHP\v5.5\extras\ssl\openssl.cnf
  16. Ensure that you give the proper security permissions for PHP and the Temp Folders
  17. Download Owncloud and unzip it to a folder of your choice
  18. Configure the default apppool to not run any managed code
  19. Goto the Default Website and then set the following
  20. Request Filtering > Http verbs, should be empty
  21. Click on edit feature setting and change Maximum allowed content length to 4187593113
  22. Goto handler mappings and allow all verbs for php via fast cgi
  23. If you get the following prompt, just enclose the executable in quotation
  24. Now map the Default Website directory to the owncloud folder
  25. Open localhost to test and follow the prompts to setup Owncloud

Good luck!

Categories: IIS