Вы находитесь на странице: 1из 2

Using Memcached Session State Provider

- Download Memcached Providers release and unzip it.

- Download Memcached for win32 from


http://jehiah.cz/projects/memcached-win32/ for version 1.2.1 and from
http://www.splinedancer.com/memcached-win32/ for version 1.2.4. (This
version supports multiple Get method).

- Create a new database in SQL Server 2005 name “session”.

- Run the scripts under DbSQL to create table and stored procedures
necessary to run the Memcached Session State Provider.

- Create a new ASP.net Web Application Project.

- Right mouse click on the references folder in the project and click on “Add
Reference” option. Go to the location where Memcached Providers were
unzip and select Enyim.Cache.dll, MemcachedProviders.dll & Log4net.dll.
Then click “OK” to add them to the project.

This document is provided under the “Apache License Version 2.0, January 2004” 1
http://www.apache.org/licenses/
- Open Web.config file and add the following section to configSections tag
<sectionGroup name="enyim.com">
<section name="memcached"
type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>

- Add the following section to configure Enyim’s client to point to


Memcached servers
<enyim.com>
<memcached>
<servers>
<!-- put your own server(s) here-->
<add address="127.0.0.1" port="11211" />
</servers>
<socketPool minPoolSize="10" maxPoolSize="100"
connectionTimeout="00:00:10" deadTimeout="00:02:00" />
</memcached>
</enyim.com>

- Create a connection string to “session” database.


<connectionStrings>
<add name="SqlSessionServices"
connectionString="Data Source=.;Initial Catalog=Session;User Id = sa; Password = sa;"/>
</connectionStrings>

- Add the following section to configure Memcached Session State


Provider.
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom"
customProvider="MemcachedSessionProvider">
<providers>
<add name="MemcachedSessionProvider"
type="MemcachedProviders.Session.SessionStateProvider,MemcachedProviders"
connectionStringName="SqlSessionServices" dbType="SQL"
writeExceptionsToEventLog="false" />
</providers>
</sessionState>

- Add following section to configure log4net


<log4net>
<!-- Define some output appenders -->
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}]
- %message%newline" />
</layout>
</appender>
<!--<threshold value="OFF" />-->
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="WARN"/>
<appender-ref ref="ConsoleAppender">
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="WARN"/>
<levelMax value="FATAL"/>
</filter>
</appender-ref>
</root>
</log4net>

- Now you can use Session object to use Memcached as Session State
Storage.

This document is provided under the “Apache License Version 2.0, January 2004” 2
http://www.apache.org/licenses/

Вам также может понравиться