Problems and summary of using appfabric cache to store Asp.net sessions

Source: Internet
Author: User

After one day, the test environment was initially established. The steps are as follows:

Install and configure appfabric here. Go straight to the topic.

 

1. Create an Asp.net website and use. Net 4.0,. net2.0, and 3.5.


2. Add reference.
For 32-bit machines, the cache class library is located below:

C: \ windows \ system32 \ appfabric \ microsoft. applicationserver. caching. Client. dll
C: \ windows \ system32 \ appfabric \ microsoft. applicationserver. caching. Core. dll

If it is a 64-bit win2008 server, the cache class library is located below:

C: \ windows \ sysnative \ appfabric \ microsoft. applicationserver. caching. Client. dll
C: \ windows \ sysnative \ appfabric \ microsoft. applicationserver. caching. Core. dll

Of course, it should be okay to copy these two files directly to a convenient location for reference.

 

It is very strange that the sysnative directory cannot be found directly under the Windows directory, but it can be found by adding a reference. What is Ms doing for a while?

After reading the following post, I learned that the sysnative directory does not exist. It is a directory redirection mechanism in windows.

Magic sysnative folder http://leonax.net/p/2601/magic-of-sysnative-folder/


3. Then, modify web. config.

The complete content is as follows:

<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>
<Hosts>
<Host name = "bobw.toppc" cacheport = "22233"/>
</Hosts>
<Securityproperties mode = "NONE" protectionlevel = "NONE"/>
</Datacacheclient>
<System. Web>
<Sessionstate mode = "Custom" customprovider = "appfabriccachesessionstoreprovider">
<Providers>
<! -- Specify the named cache for session data -->
<Add name = "appfabriccachesessionstoreprovider" type = "Microsoft. applicationserver. caching. datachesessionstoreprovider" cachename = "default"/>
</Providers>
</Sessionstate>
<Compilation DEBUG = "true" targetframework = "4.0">
<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>
</System. Web>
</Configuration>

The two lines in bold above are worth noting.<Securityproperties mode = "NONE" protectionlevel = "NONE"/>The following error is reported.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser error message: errorcode <errca0017>: substatus <es0006>: There is a temporary failure. please retry later. (one or more specified cache servers are unavailable, which cocould be caused by busy network or servers. ensure that security permission has been granted for this client account on the cluster and that the appfabric caching service is allowed through the firewall on all cache hosts. retry later .)

 
I did this step by step according to the guidance of the following Ms. I did not mention this sentence in it, so I tried it multiple times and failed. I simply gave a warning and suggestion, I think it implies that this sentence should be added. However, this... this is too obscure. It is really not like the MS style. In fact, this sentence is included in the XML configuration file during appfabric installation, but I did not expect it to be added here, we strongly recommend that you modify this Guidance Post in ms.

 

Configure ASP. NET session StatusProgram(Windows Server appfabric cache)

Http://msdn.microsoft.com/zh-cn/library/ee790859.aspx

 

Warning

We recommend that you specify the name of the cache hostWeb. configFile security.

 

Or in the post of the ldljscsi brother, add this sentence first.<Securityproperties mode = "NONE" protectionlevel = "NONE"/>.

Configure the ASP. NET Website to use appfabric caching to store session data.
Http://blog.csdn.net/ldljlq/article/details/5801765

 

WhileCachename = "default"This property is stored on the web. config always prompts that the 'cachename' attribute is not allowed. I thought this was not the case, but I didn't know it. It's okay, but the cache must be correct, if the specified cache is wrong or has not been created, the following error is returned.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser error message: errorcode <errca0009>: substatus <es0001>: cache referred to does not exist. Contact administrator or use the cache administration tool to create a cache.

Source error:
Line 18: <providers>
Line 19: <! -- Specify the named cache for session data -->
Line 20: <Add name = "appfabriccachesessionstoreprovider" type = "Microsoft. applicationserver. caching. datachesessionstoreprovider" cachename = "default123"/>
Line 21: </providers>
Line 22: </sessionstate>

4. Write the session into the cache.

using system;
using system. collections. generic;
using system. LINQ;
using system. web;
using system. web. ui;
using system. web. UI. webcontrols;

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Session ["username"] = "lzd ";
}
}
Protected void btnget_click (Object sender, eventargs E)
{
If (session ["username"]! = NULL)
{
Response. Write (session ["username"]);
}
}
}

 

Use get-cachestatistics default to count the cache data before and after running, and you can see that the session has been saved.

PS c: \ windows \ system32 \ windowspowershell \ V1.0 \ modules \ distributedcacheadministration> Get-cachestatistics default

Size: 0
Itemcount: 0
Regioncount: 0
Requestcount: 0
Misscount: 0

 

PS c: \ windows \ system32 \ windowspowershell \ V1.0 \ modules \ distributedcacheadministration> Get-cachestatistics default

Size: 265
Itemcount: 1
Regioncount: 1
Requestcount: 1
Misscount: 1

 

5. exceptions related to key referred to does not exist.

Some friends said they occasionally encountered the following errors.

Errorcode <errca0006>: substatus <es0001>: Key referred to does not exist. Create Objects Based on a key to fix the error.

I tried for a while and failed to reproduce this exception.

I searched again and found several links below, which are similar. This exception does not often occur, but does exist. Ms also admitted that such a bug exists on Windows azure appfabric, it has been fixed in 2011 release l release.

The Windows azure caching service and Windows Server appfabric caching are based on the sameCodeLibrary, so the developer experience is the same as the internal cache.
Therefore, I think this problem also exists in non-azure appfabric, and I don't know if MS has solved it in V1.1 CTP.

Http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/024a5775-73d2-44f8-8701-2e9d2ecbd345/
Http://social.msdn.microsoft.com/Forums/en-MY/windowsazuredevelopment/thread/024a5775-73d2-44f8-8701-2e9d2ecbd345
Http://social.msdn.microsoft.com/Forums/en-US/velocity/thread/947663ce-f423-487f-a501-cb023295ebcb

Http://social.msdn.microsoft.com/Forums/en-US/velocity/thread/df0231d8-3d51-4d61-9b2a-4e34a64c002a

 

In my opinion, we have always put the session on the State server. In fact, apart from being unable to share the memory of multiple machines, it is similar to appfabric in other aspects and is an independent service, they all have independent ports, and the State Service has been tested for a long time and is very stable. However, appfabric has just come out and has some bugs and so on. You should use it with caution.

 

References:

Prepare the cache client development environment (Windows Server appfabric cache)
Http://msdn.microsoft.com/zh-cn/library/ee790876.aspx

Configure ASP. NET session Status provider (Windows Server appfabric cache)

Http://msdn.microsoft.com/zh-cn/library/ee790859.aspx

Configure the ASP. NET Website to use appfabric caching to store session data.
Http://blog.csdn.net/ldljlq/article/details/5801765

Appfabric configuration error
Http://social.msdn.microsoft.com/Forums/en-US/velocity/thread/f3b579b4-6448-4308-88c7-34f412d3ea59/

Configuration settings for the ASP. NET 4 caching session State provider
Http://msdn.microsoft.com/en-us/library/windowsazure/gg185682.aspx

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.