Deleting file to Recycle Bin using C#

February 26, 2015 Leave a comment

At first glance, there is no library/dll in C# that will automagically delete a file to the recycle bin. However if you were to look around, there is a function inside VB which does this.

The good thing about .NET is that everything is just libraries, VB, C# these are just the high level programming languages and you are free to use any function across the board.


So in order to delete a file to recycle bin inside a c# app, first add a reference to Microsoft.VisualBasic



Then inside your code you just do this




For more details on that function, you can refer to

Categories: ASP.NET

Optimizing AppFabric 1.1 for Session State

February 24, 2015 Leave a comment

Amazingly although there are a lot of resources on using AppFabric for SessionState, there is no single site that attempts to give you all the necessary settings in order to run Appfabric for session state properly


Here are some of the settings which you need to use in order to optimize AppFabric

Type Parent Setting Reason
AppFabric Settings > Advancedproperties <transportProperties maxBufferPoolSize=”2147483647″ maxBufferSize=”2147483647″ /> Session states might be big (imagine those with huge gridviews) so putting it as a bigger size is necessary in order not to encounter errors with too small size to store viewstate
AppFabric Settings > Advancedproperties <partitionStoreConnectionSettings leadHostManagement=”false” /> If you are using a HADRON setup for SQL Server, you might want to set leadhostmanagement to false so that SQL manages the cache cluster rather than lead hosts, this way as long as SQL is up, your caching service is always up.

If you use lead hosts, make sure that there is always at least 2 lead host active else the ENTIRE cluster will go down

For more details refer to

AppFabric Powershell Set-CacheConfig -CacheName Web-Session -Eviction None Make sure the Eviction property for the session cache is set to none instead of LRU else some weird things may happen during eviction
AppFabric Powershell
new-cache MyCache -Secondaries 1
Enable secondaries for the session state, you don’t want things to go missing just because a server went down
Application Ensure you are running the latest cumulative update for AppFabric (as of writing CU5)
Infrastructure Appfabric is designed for scale out rather than scale up, so 4 servers with 32gb of ram is better than 2 servers with 64 gb of ram. In fact the more servers the merrier.

Additionally the more servers there are, the better the performance since more servers can respond to the requests

Infrastructure For high availability and best performance, use SQL server rather than file server
web.config Ensure you are running the latest DLL for AppFabric
web.config sessionState Ensure you are using Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider as the Session provider
web.config sessionState useBlobMode=”false” Set useblobmode = false so that the web server only grabs what it needs rather than the entire session. However if your application generally uses everything in session, then set this to true instead so that lesser round trips are needed
web.config dataCacheClients <transportProperties connectionBufferSize=”131072″ maxBufferPoolSize=”104857600″

maxBufferSize=”104857600″ maxOutputDelay=”2″ channelInitializationTimeout=”60000″


update the transport properties to be the same as appfabric settings (or lesser) so that appfabric can optimize the connections
web.config dataCacheClients <localCache isEnabled=”true” sync=”TimeoutBased” objectCount=”1000″ ttlValue=”600″ /> Enable localcache so that some items can be stored locally instead of constantly grabbing from the server
Categories: AppFabric

Changes in web.config between AppFabric 1.1 vs AppFabric 1.1 CU [x]

February 12, 2015 Leave a comment

If you are using AppFabric 1.1 (without any cumulative updates), you will need the following DLLs inside the bin folder

  1. Microsoft.WindowsFabric.Common.dll
  2. Microsoft.WindowsFabric.Data.Common.dll
  3. Microsoft.ApplicationServer.Caching.Client.dll
  4. Microsoft.ApplicationServer.Caching.Core.dll

and you will be using the following code segments

<section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" />

   <localCache isEnabled="true" sync="TimeoutBased" objectCount="1000" ttlValue="600" />
     <host name="host01" cachePort="22233" />
     <host name="host02" cachePort="22233" />

<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
     <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="cacheName" sharedId="sharedID" />


If you upgrade to any CU (currently at CU5), note that there are a few changes made to appfabric client configuration (changes in red)

You will need the following DLLs inside the bin folder

  1. Microsoft.WindowsFabric.Common.dll
  2. Microsoft.WindowsFabric.Data.Common.dll
  3. Microsoft.ApplicationServer.Caching.Client.dll
  4. Microsoft.ApplicationServer.Caching.Core.dll
  5. Microsoft.Web.DistributedCache.dll


Code segments have also been modified

<section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" />


  <dataCacheClient name="default">
    <localCache isEnabled="true" sync="TimeoutBased" objectCount="1000" ttlValue="600" />
      <host name="host01" cachePort="22233" />
      <host name="host02" cachePort="22233" />

<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
    <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" cacheName="cacheName" useBlobMode="false" applicationName ="sharedID" />

Categories: AppFabric

Setting up AppFabric on Windows 2012R2

February 12, 2015 Leave a comment

As an update to, here are the steps to install AppFabric on a CLEAN install of Win2012R2


Not the first time?

Goto Groups Management and delete the AS_Administrators and AS_Observers groups


Preflight Check

  1. AppFabric 1.1: Download from
  2. AppFabric 1.1 CU 5: Download from
  3. Windows Server 2012R2 DVD mounted on D Drive


Setting up AppFabric Pre-Requisites

Use the following powershell script to setup all the necessary pre-requisites for AppFabric

#ensures running as admin
$RunningAsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

if (!$RunningAsAdmin)
    Write-Warning "Must be executed in Administrator level shell."
    Write-Warning "Script Cancelled!"

$Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings

if ($Updates.ReadOnly -eq $True) { Write-Error "Cannot update Windows Update settings due to GPO restrictions." }

else {
    $Updates.NotificationLevel = 4 #Enable
    $Updates.ScheduledInstallationDay  = 0
    Write-Output "Automatic Windows Updates enabled."
Install-WindowsFeature Web-WebServer, Web-Mgmt-Console, NET-Framework-Core,Web-Default-Doc, Web-Dir-Browsing, Web-Http-Errors,Web-Static-Content, Web-Http-Logging, Web-Stat-Compression, Web-Filtering -IncludeManagementTools -Source D:\Sources\Sxs

Installing AppFabric

  1. Run the AppFabric Installer WindowsServerAppFabricSetup_x64.exe
  2. Accept the license agreement and click Next
  3. Decide whether you want to help Microsoft with the setup experience and then click Next
  4. Just click Next
  5. To be on the safe side, checkbox everything and click Next
  6. Click install and wait for the installation to be completed
  7. Once it is done, uncheck Launch configuration tool and click Finish
  8. Now double click on AppFabric1.1-KB2932678-x64-ENU and install AppFabric 1.1 CU5
Categories: AppFabric

Running Bitnami LAMP stack in HyperV

September 21, 2014 1 comment

Bitnami has several nice prebuilt linux machines that is very useful for quick deploy.


In order to make it easier, you just need to setup a base image for the Bitnami LAMP stack VM


Download these first

Bitnami LAMP Stack: Goto and grab the vmware virtual machine image

Microsoft Virtual Machine Converter Solution Accelerator 2.0: Goto and grab the msi file


Convert VMDK to VHD

Run an administrative powershell instance and run the following 2 commands

# Import the MVMC cmdlets
Import-Module ‘C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1’


#Convert the VMDK to VHDX

ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath bitnami-lampstack-5.4.32-0-ubuntu-14.04.vmdk -DestinationLiteralPath bitnami-lampstack-5.4.32-0-ubuntu-14.04.vhdx -VhdType DynamicHardDisk -VhdFormat Vhdx


Once the conversion is complete, use the HyperV –> Edit Disk function to compact the VHDX to save space

Create HyperV VM

Once done, just create a normal VM, there is no need to restrict yourself to the legacy network adapters, the new one works fine




Setting up your bitnami VM

Follow the guide found at


You can also refer to for some of the more administrative functions


Updating Integration Services

Issue the following command: sudo pico /etc/initramfs-tools/modules


Add these 4 items to the end of the file



Now rebuild the boot image

sudo update-initramfs –u


The guest OS needs to be rebooted:

sudo shutdown -r now

After the virtual machine reboots, run the following command to check if the modules are enabled:



Categories: HyperV

Common Setup Commands for Ubuntu 12.x onwards

September 20, 2014 1 comment

To change the hostname of the machine
sudo nano /etc/hostname

sudo nano /etc/hosts

To change the IP Address of the machine

sudo vi /etc/network/interfaces

auto eth0
iface eth0 inet static

sudo /etc/init.d/networking restart

To change the account password


To shutdown the machine

sudo shutdown –h 0


To install and enable openssh

sudo apt-get update
sudo apt-get install openssh-server
sudo ufw allow 22


sudo nano /etc/ssh/sshd_config
# line 28: uncomment and change ‘no’
# default setting "without-password" means that root login is permited but require keys authentication
PermitRootLogin no


sudo initctl restart ssh

Categories: Ubuntu

Seafile end to end encryption for encrypted libraries (v3)

May 11, 2014 Leave a comment

Rephrased from and

FYI, encryption used are all symmetric

Master Key
When you create an encrypted library, a random file key (master key) is generated. This master key is the main key that is used to encrypt and decrypt the files and this key has NOTHING to do with your password, and is not stored anywhere in the system. As long as you can get this key, your access to the data is confirmed! There is also no known way to change this easily.

Enc Master Key
The password you entered is used to encrypt the master key (enc master key) , this data is stored in the server to send out to the clients in order to derive the actual file key by decrypting with the password.
I.e master key enc master key

Web Browsers (8000, 8082)
For browsers and all access thru http protocols (inc mobile devices) the enc master key and encrypted data is sent to the client/server and the client/server will do the neccessary decryption to get the file key which is then used to decrypt the encrypted data to get the actual file. For mobile apps, it seems the file key is also stored in the app data.

cc net (10001) and seaf daemon (12001)
A magic token is generated from the library id and password and stored on the server. This is used to confirm the password is correct. Once it is confirmed, the master key is stored on the client.

Although no passwords are stored anywhere, this does not really matter since all it does is to decrypt the encrypted master key, what really matters is the file key, which unfortunately seems to be stored on both the client as well as mobile app, quite possibly in an unencrypted format.

So while the sys admin is not able to your files. Should your devices be compromised, the hackers potentially have access to your file key which will unlock the files when they request it from 8082 which does not need any form of authentication.

Categories: Uncategorized

Get every new post delivered to your Inbox.