Archive

Archive for February, 2015

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

image

 

Then inside your code you just do this

image

 

 

For more details on that function, you can refer to https://msdn.microsoft.com/en-us/library/ms127976%28v=vs.110%29.aspx

Advertisements
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

<td valign="top" 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 here

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 [dot] Web [dot] DistributedCache [dot] 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″

receiveTimeout=”600000″/>

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" />

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

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

 

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" />

 

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

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

Categories: AppFabric

Setting up AppFabric on Windows 2012R2

February 12, 2015 1 comment

As an update to https://jefferytay.wordpress.com/2014/01/07/appfabric-on-windows-server-2012-r2/, 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
image

 

Preflight Check

  1. AppFabric 1.1: Download from http://www.microsoft.com/en-sg/download/details.aspx?id=27115
  2. AppFabric 1.1 CU 5: Download from http://www.microsoft.com/en-sg/download/details.aspx?id=42281
  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!"
    return;
}

$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
    $Updates.Save()
    $Updates.Refresh()
    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
    image
  3. Decide whether you want to help Microsoft with the setup experience and then click Next
    image
  4. Just click Next
    image
  5. To be on the safe side, checkbox everything and click Next
    image
  6. Click install and wait for the installation to be completed
  7. Once it is done, uncheck Launch configuration tool and click Finish
    image
  8. Now double click on AppFabric1.1-KB2932678-x64-ENU and install AppFabric 1.1 CU5
Categories: AppFabric