Windows Azure Cloud Service (15) how to handle ASP. VM Instance-Alibaba Cloud developer community in multiple NET Session scenarios

Catalogue of Windows Azure Platform series articles

 

 

 Update 2015-04-06

the author summarizes how to deal with Session in Azure. Please refer to the latest documents:

Windows Azure HandBook (4) Analysis Windows Azure how to Handle Session

 

 

 

Update 2015-03-10

for the method of retaining Instance for multiple Session, Microsoft's official suggestions are as follows:

1. Using Redis Cache

2. In The PaaS Cloud Service, use In-Role Cache to retain Session

3. Save the Session to the SQL Server VM and configure Always-On for high availability.

 

In addition, according to Microsoft's official documents http://support.microsoft.com/kb/2006191

for Asp.net applications, Microsoft does not support saving Session to SQL Azure.

The workarounds provided here do not work for ASP.Net SQL Session State Management features. Microsoft does not support SQL Session State Management using SQL Azure databases for ASP.net applications.

  

   Update the following content has been retired on 2015-03-10

traditional ASP.NET applications are stateless, but we can use Session to save user status, such as saving user names and passwords. And in general, the logical services of some deployed applications are mostly based on the Session status, which is stored on the Web server of our Lan Session.

If you deploy a Windows Azure managed service for a single compute node (1 instance), the Session is stored on the managed server. However, this will lead to a problem: As I mentioned in the previous chapters, Fabric Controller will automatically monitor the execution status of computing nodes. If the computing node of a single instance that we deploy encounters some problems (such as hardware failure or downtime), the Fabric Controller automatically finds different servers and restarts the computing node. That will allow our managed services in a short time cannot normal operation and service, reliability decreased.

To improve the reliability of the Windows Azure, microsoft recommends a managed service need at least 2 instance . This ensures that if one compute node fails to provide normal services, the other compute node will continue to run and provide services.

Assume that the Windows Azure instance count has been set to two compute nodes (such as A and B), then we also know that the Windows Azure automatically provides Load balancing (Load Balance,LB). In this case, all our businesses are processed by compute node A in A certain period of time. After A period of time, A processes complex compute services, LB will directly handle the request to compute node B. However, the Session stored on compute node A is lost! Compute Node B does not know the previous Session.

 

Therefore, if we want to migrate existing Web applications to Windows Azure platform, we need to pay great attention to the processing of Session.

1. For the Windows Azure hosting service of a compute node (1 instance), use the existing "Session[SESSION_NAME_KEY]" to process the business logic normally. However, the reliability may be reduced due to hardware faults on computing nodes.

 

II. For two compute nodes above (2 instance or more) Windows Azure managed Services, in order to ensure Session can persistence, we need to an existing Web application modified On:

(1) use Azure Table Storage to save Session. You can download the sample code here.

You can download this provider by looking for Windows Azure Platform Training kit. In this toolkit, there is a sample project called AspProviders. You can directly add this project to your solution, or use Assembly reference to add that DLL to your project.

If you reference this assembly, you must modify your web.config file. Open your configuration file and find the element. Delete the existing configuration and paste the following code. When you do this, remember to write down your real application name.

 

 <!--SessionState Provider Configuration-->
<sessionState mode="Custom" customProvider="TableStorageSessionStateProvider">
<providers>
<clear/>
<add name="TableStorageSessionStateProvider"
type ="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider"/>
</providers>
</sessionState>

 

 

-The principle is to save our Session as an object to Windows Azure Table, and then take it out when necessary for use.

Advantages:

-The price is cheaper than that of SQL Azure. Windows Azure Storage only costs $0.15 per 1GB per month.

Disadvantages:

-Cannot get official support from Microsoft.

-The performance may not be very good (I have tested it, and sometimes the performance is not good).

-You need to clean up Session that have been used before.

 

(2) use SQL Azure Session Provider to save Session. For details, see MSDN blog.

-The principle is to save our Session as an object to SQL Azure Table, and then take it out when necessary for use.

Advantages:

-Although the price is not as cheap as Table Storage, it is still affordable.

Disadvantages:

-Cannot get official support from Microsoft.

-You need to clean up Session that have been used before.

Each time Session, a new table is created to save the Session. For subsequent Session requests, check whether the table already exists. Therefore, once the Session times out, we need to delete the Session table that times out. To automatically delete expired Session, most of us use Windows Azure Worker Role to delete tables.

 

(3)AppFabric Caching

AppFabric Caching is actually an option recommended by Microsoft and is officially supported by Microsoft. AppFabric Caching cache service in distributed memory. It is a Windows Server AppFabric Caching based on automatic configuration.

Advantages:

-Cache in memory, fast access-Microsoft official support

disadvantages:

-The price is higher than the above two methods. The starting price is 128M $45, and the maximum price is 4GB $325.

 

Reference: Various Options to Manage Session State in Windows Azure

 

 

Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now