Asp. NET cross-app sharing session and using Redis for session hosting

Source: Internet
Author: User
Tags connection pooling hosting

Source Reference Network article

The following four modes are available in the session processing method provided by ASP:

1. InProc mode

  This is the ASP. NET default session management mode, which maintains the session within the application process.  2,  stateserver mode   This is installed on the server. NET environment after a StateServer service, in the application process management session, can be multi-application session sharing, in my opinion this model is most suitable for the Web garden mode. This has been said in previous blogs.  3,  sqlserver mode   This is hosting the session using SQL Server. The advantage is that SQL Server can be used to deal with the massive session, outside the application process, durable, high security advantages. SQL Server mode is ideal for Web farm environments  4,  custom mode   This is a custom mode, it is very large, and in the case of owning provider, this mode can be used to play, Use a variety of data storage programs for session management.          in the use of StateServer, SQL Server mode, there is a very difficult problem: Session name control problem. When ASP. NET handles this problem, in order to ensure the unification of the application, ASP. NET hashes each app ID hosted on IIS and serves as a prefix stored in the database for SessionID. This leaves a problem, if there are multiple applications on a single server, you must ensure that each app's ID is exactly the same on different servers, or there will be a tragedy that the session cannot share. While we are deploying applications in order to tolerate disaster, it is entirely possible to put multiple applications on a single server, so be sure to note the consistency of the app IDs in IIS. A more troublesome usage is to use reflection to modify the SessionID generation rules or modify the database stored procedures, forcing the unification of the prefix, this method is more cumbersome, and to a certain extent, reduce the performance of the application, it is not recommended.          I'm using this provider:harbour.redissessionstatestore,         GitHub:Https://github.com/TheCloudlessSky/Harbour.RedisSessionStateStoreThis provider was developed on the basis of Servicestack.redis as a Redis driver. It's very easy to use, first of all, to build your Redis environment, add Harbour.redissessionstatestore, Servicestack.redis, and then modify the configuration of Web. config as follows:
<system.web>  <sessionstate mode= "Custom" customprovider= "Redissessionstateprovider" >     < providers>       <clear/>       <add name= "Redissessionstateprovider"            type= " Harbour.RedisSessionStateStore.RedisSessionStateStoreProvider "            host=" localhost:6379 "clienttype=" pooled "/ >     </providers>   </sessionState> </system.web>

ClientType is set to pooled connection pool mode by default. If you do not use the connection pooling mode, modify to a different string (empty is also considered pooled mode).

This provider has a feature that does not prefix the session with the app ID, which is exactly what I need, which is more convenient for session sharing between multiple systems.

This is done with the Redis hosted session.

Asp. NET cross-app sharing session and using Redis for session hosting

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.