This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19063|Reply: 0

[ASP.NET] . Net distributed architecture: Session sharing based on Redis

[Copy link]
Posted on 10/15/2018 1:26:55 PM | | | |
1: Introduction to Session

What is Session? Simply put, it is a number given to the client by the server. When a web server is running, there may be several users browsing websites that are running on that server. When each user first connects to the web server, he establishes a session with the server, and the server automatically assigns it a SessionID to identify the user's unique identity. This SessionID is a 24-character string randomly generated by the web server, and we'll see it in action in the experiment below.

2: Centralized mode and configuration of the Session in the Asp.Net

(1): InProc, Session is stored in the process, which is also the storage method in the ASP.Net and is also the default value
(2): StateServer, Session is stored in a separate state service, i.e., ASP.NET State Service
(3): SQLServer, Session is stored in the SQL Server database
(4): Custom, a custom save method, which can be saved in Oracle, SQLServer, MongoDb, and Redis
This article mainly talks about the storage and sharing of Sessions in Redis

3: Session Provider configuration based on Redis

(1) Make the following changes to the HomeControllers of Sites A and B, as shown in the figure below, and add the functions of creating and obtaining sessions


The corresponding View views


   (2) RedisProvider configuration: Microsoft.Web.RedisSessionStateProvider
Install Microsoft.Web.RedisSessionStateProvider with Nuget as shown in the following image:

        Modify the profile:



4. Load balancing session test

(1) Enter in the browser:http://192.168.152.128/   Create a Session


     (2) Enter in the browser:http://192.168.152.128/home/getsessionvalue, Open two tabs, be sure to open them in the same browser window, otherwise the SessionID will definitely be different


From the figure, you can see that site A shares the sessions created by site B.
You can also see the Session you just created from redis as shown in the figure below







Previous:Asp.Net MVC native EF insertion, the correct way to update the data
Next:Angular6 introduces jquery and bootstrap
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com