A day with .Net

My day to day experince in .net

Archive for the ‘Windows Server AppFabric Caching’ Category

Configure AppFabric Server for Session State using power shell

Posted by vivekcek on December 17, 2012

In this post i am going to tell you about some problems you may experience when using AppFabric server as your caching state provider. Please note that i am using AppFabric 1.0 (WindowsServerAppFabricSetup_x86_6.1/x64). The commands for 1.1 version may be different.

So first of all you must download and install AppFabric 1.0. Refer my old blog.Install Windows Server AppFabric Caching

After successful installation go to Cache Administration Power Shell. Issue the following commands. You must run the power shell in Administrator mode.Also i hope you have only one cache host in your cluster.

1.

Get-CacheHost

The above command shows the status of the cache host.The cache host may be DOWN or UP.If host is DOWN issue the below
command.

2.

Start-CacheHost

Now issue

3.

Start-CacheCluster

Now give permission for all client accounts by

4.

Grant-CacheAllowedClientAccount everyone

Do a restart

5.

Restart-CacheCluster

Disable Security for session State Provider

This step is very important. In this step you will disable security mode in cache server through power shell.Use the below

command for that.

6.

Set-CacheClusterSecurity -ProtectionLevel None -SecurityMode None

Now you need to specify this in your web config file of asp.net application as below.

7.

<dataCacheClient>
    <hosts>
        ...
    </hosts>

    <securityProperties mode="None" protectionLevel="None" />
</dataCacheClient>

some time you may experience the below error

ErrorCode :SubStatus:The connection was terminated, possibly due to server or network problems or serialized Object size is greater than MaxBufferSize on server. Result of the request is unknown.

To handle this we have to change the configuration in server side and clients web.config.

1. In power shell export the server configuration to a directory by using the below command

Export-CacheClusterConfig -File [yourfilepath] 

2. Open the file using notepad and add the blow tag and save the file.

<advancedProperties>      
    <transportProperties maxBufferSize="8388608" />
</advancedProperties> 

3. Now stop the cluster.Import the saved config file and restart cluster.

Stop-CacheCluster 
Import-CacheClusterConfig -File [yourfilepath]
Start-CacheCluster

4. In the web.config of client add the below.

<dataCacheClient>
    <hosts>
        ...
    </hosts>

    <securityProperties mode="None" protectionLevel="None" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456" 
                       maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000" 
                       receiveTimeout="600000"/>
</dataCacheClient>

The full Cache Server config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="dataCache" type="Microsoft.ApplicationServer.Caching.DataCacheSection, 

Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </configSections>
    <dataCache size="Small">
        <caches>
            <cache consistency="StrongConsistency" name="default">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
        </caches>
        <hosts>
            <host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
                hostId="1326169401" size="895" leadHost="true" account="MACHINE1\Administrator"
                cacheHostName="AppFabricCachingService" name="Machine1" cachePort="22233" />
        </hosts>
        <advancedProperties>
            <securityProperties mode="None" protectionLevel="None">
                <authorization>
                    <allow users="everyone" />
                    <allow users="IIS_IUSRS" />
                    <allow users="Administrator" />
                    <allow users="NETWORKSERVICE" />
                    <allow users="MACHINE2\Administrator" />
                </authorization>
            </securityProperties>
        </advancedProperties>
    </dataCache>
</configuration>

The full web config

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <configSections>
    <section name="dataCacheClient" 

type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,Microsoft.ApplicationServer.Caching.Core, 

Version=1.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere"/>
  </configSections>
  <dataCacheClient>
    <localCache isEnabled="true" sync="TimeoutBased" objectCount="1000" ttlValue="600"/>
    <hosts>
     <host name="Machine1" cachePort="22233"/>
    </hosts>
<securityProperties mode="None" protectionLevel="None" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456" 
                       maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000" 
                       receiveTimeout="600000"/>
  </dataCacheClient>
  <system.web>
<machineKey 

validationKey='AFD1EF00AB1FDE92459609D9322D97D5B47627B331FC4600248ADD5CBF2454641010B0A12EB87A2E00B39E07575132374B1486A4471E0

6E37C9740DD97EDE3D3'   decryptionKey='B32BDECF54ADED4DE7106A42A78B6E1358A9AE9212D512C6'   validation='SHA1'/>
    <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
      <providers>
        <add name="AppFabricCacheSessionStoreProvider" 

type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="default" sharedId="MvcApplication"/>
      </providers>
    </sessionState>
    <compilation>
      <assemblies>
        <add assembly="Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, 

PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, 

PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <httpRuntime />
 <customErrors mode="Off"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Advertisements

Posted in Windows Server AppFabric Caching | Tagged: , , , | Leave a Comment »

Windows server appfabric cluster configuration using two work group machines

Posted by vivekcek on November 24, 2012

Read my post about installing windows server app fabric caching in a single WoRKGROUP computer.
Link To Post

In this post i am going to explain how to install appfabric in 2 networked WORKGROUP computer.

Configure the 2 system.
—————————————

1. Ensure that both systems are in a work group named ‘WORKGROUP’.
2. Down load and save the appfabric set up in 2 systems.
3. Create an Administrator account in both systems with same username.

Install appfabric in first machine.

——————————————-

1. Log in to first machine using the WORKGROUP\Administrator account. Simply type WORKGROUP\Administrator in Username text box.

2. By pressing SHIFT Right click the setup. Then select ‘Run As Different User’ use WORKGROUP\Administrator. Complete the installation.

3. Click Start, click All Programs, click Windows Server AppFabric, and then press SHIFT and right-click Configure AppFabric. Click Run as a different user. Enter \ and the password, and then click OK.

4. For Caching Service account, click Change. Click Custom account, click Browse, select WORKGROUP\Administrator

5. In the Caching Service configuration provider box, select XML.

6.In the File Share box, enter the computer name and share name for the file share that you created in the “Preparing Workgroup Computers for Installing AppFabric” topic for the XML file that will store caching configuration information. The path and name must be in the UNC format, i.e., \\\. On this first computer that will contain the share, you can browse to it.

7.Keep the default settings of New cluster selected and Cluster size set to Small (1-5 Machines). Click Next.

8.On the Configure AppFabric Cache Node page, keep the default port settings, and select the Windows Server AppFabric: AppFabric Caching Service and Remote Service Management firewall exceptions. Click Next and then Yes.

9. Open the Windows PowerShell console with the ApplicationServer module by clicking Start, clicking Control Panel, clicking Administrative Tools, and then double-clicking Windows PowerShell Modules.

10. To start the cache cluster, execute the Use-CacheCluster cmdlet to determine the cluster that this computer can administer, and then execute the Start-CacheCluster cmdlet.

Install appfabric in second machine.
—————————————————–

1. Log in to second machine using the WORKGROUP\Administrator account. Simply type WORKGROUP\Administrator in Username text box.

2. By pressing SHIFT Right click the setup. Then select ‘Run As Different User’ use WORKGROUP\Administrator. Complete the installtion.

3. Click Start, click All Programs, click Windows Server AppFabric, and then press SHIFT and right-click Configure AppFabric. Click Run as a different user. Enter \ and the password, and then click OK.

4. For Caching Service account, click Change. Click Custom account, click Browse, select WORKGROUP\Administrator

5. In the Caching Service configuration provider box, select XML.

6. In the File Share box, enter the computer name and share name for the file share created for the XML file that will store caching configuration information on the first computer added to the workgroup. The path and name must be in the UNC format, i.e., \\\.

7.Select Join cluster, and then select the cluster. Click Next.

8.On the Configure AppFabric Cache Node page, keep the default port settings, and select the Windows Server AppFabric: AppFabric Caching Service and Remote Service Management firewall exceptions. Click Next and then Yes.

9.On the Configure Application page, click Finish.To start the cache cluster, execute the Use-CacheCluster cmdlet to determine the cluster that this computer can administer, and then execute the Start-CacheCluster cmdlet.

GO to first machine and give power shell command.

Grant-CacheAllowedClientAccount everyone

Posted in Windows Server AppFabric Caching | Leave a Comment »

Access Windows Server AppFabric Cache through c# code

Posted by vivekcek on November 12, 2012

In this post i will explain how to add data to Windows Server AppFabric Cache.

1. Create a console application.

2. Add reference to Caching dll’s.

3. Use the below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ApplicationServer.Caching;

namespace AppFabricCache
{
    class Program
    {
        static DataCacheFactory _cacheFactory = Initialize();  
        static void Main(string[] args)
        {
            var cache = _cacheFactory.GetDefaultCache();
            var Key = "mykey";
            var obj = cache[Key];
            if (obj == null)
            {
                obj = "hai";
                cache.Add(Key, obj);
                Console.WriteLine("Object added");

            }
            else
            {
                Console.WriteLine("Object was already in cache");
            }
            Console.ReadLine();
        }
        static DataCacheFactory Initialize()
        {
            var Config = new DataCacheFactoryConfiguration();
            var Servers = new List<DataCacheServerEndpoint>();
            Servers.Add(new DataCacheServerEndpoint("Poomala",22233));
            Config.Servers = Servers;
            var temp=new DataCacheFactory(Config);

            return temp;
        }
    }
}

Posted in Windows Server AppFabric Caching | Leave a Comment »

AppFabric Caching Admin Tool

Posted by vivekcek on November 10, 2012

Hope you read about my blog on installing and configuring Windows Server AppFabric.If not read here Install Windows Server AppFabric Caching.
Now i am gonna introduce you an open source AppFabric Caching Admin Tool from codeplex.

Download it http://mdcadmintool.codeplex.com/

Use it add cache cluster, regions, etc.

Use it with Admin privileges

Posted in Windows Server AppFabric Caching | Leave a Comment »

Install Windows Server AppFabric Caching

Posted by vivekcek on November 10, 2012

In this post i am going to explain how Windows Server AppFabric, the distributed caching solution from Microsoft can be installed and configured in a WORK-GROUP computer.WORK GROUP computers came under category of your stand alone home PC. In another post i will explain how AppFabric can be configured in domain system.

So what is AppFabric?
————————————-

AppFabric is a Microsoft solution for distributed caching. Currently two AppFabric’s are available one in windows azure and other Windows Server AppFabric.Both have some feature changes you can search about it in web.

Install
————————

Need windows 7(32 bit or 64 bit) or Windows Server 2008 R2.

1. Download (WindowsServerAppFabricSetup_x86.exe) Microsoft AppFabric 1.1 for Windows Server Microsoft AppFabric 1.1 for Windows Server .

2. Run Setup.

3. Select all features.

4. After installation the configuration window will be opened OR you can select config window from program menu.

5. In a Work Group computer you have to use XML as caching service provider.

6. Now create a network share folder named ‘Share’ with write permission.

7. Use browse button to set the shared folder path as UNC path.

8. In the case of Work Group computer change the service account to your user account.

9. Click next don’t change default ports. Finish installation

10. Open the Cache administration power shell with Run as Administrator command.

11. Use the Start-CacheCluster command.

In another post i will explain how to use this in .NET applications.

Posted in Windows Server AppFabric Caching | Tagged: | Leave a Comment »