Home  >  Article  >  Backend Development  >  Detailed explanation of Session distribution

Detailed explanation of Session distribution

大家讲道理
大家讲道理Original
2017-05-31 14:34:232723browse

1. Foreword & Review


Distribution in the previous articleSession In the sharing mode = Session + Redis + Nginx, many students left messages and asked me many questions. Among them, the most impressive ones are: What should I do if nginx hangs up? What are the advantages of using the Redis Session solution compared to the Microsoft Session solution? Cookie can also replace Session. What are the advantages of using Redis’ Session solution? What is the iphash method of Nginx? What is the use of MachineKey? How to implement Net Core?

When I saw everyone’s questions, my answer was only from the application level. The basic answer can be summarized as: “Others have done this and solved this problem. I also solved this problem using this method. Please see the link for the principle. "I am ashamed to say that at that time, I did not fully understand his real advantage. I just knew it was better to do this based on intuition and experience. I knew when. When some things are uncontrollable, decoupling, visualizing, and clustering them can make a system more robust, but there is no theoretical support. After consulting information and reading books in the recent period, I have a deep understanding of this. This article will analyze and explain this Session sharing from the usability perspective of the websiteArchitecture, and use .net core to implement this again. Architectural patterns. (The net core version of Session distributed sharing has no chance to be applied to the production environment, let alone past experience, so it is only for research. Please pay attention, but there are experts in the garden who have already written relevant articles. This article Relevant articles will be posted at the end)

2. Website availability--Session management


## Usability is a very important part of the website architecture. What is usability? To put it simply, it means that users can open this website anytime and anywhere, and the website can be opened, and the functions inside can be used. What happens if availability is low? Everyone imagines the scene of grabbing tickets on 12306 during the Spring Festival. The website crashes in various ways. You will definitely think: If there are other ways to buy tickets, I won’t use this broken website 12306. This example is a bit extreme because the business scenario is quite extreme. Of course, this phenomenon is not just a problem with website availability. But a website cannot be opened every three days, or every page you click on is full of error pages and no response to operations. Will you still use this website? I believe that when we browse a website, as long as it is not available like a monopoly website like 12306, we will definitely leave and look for other similar websites.

## Session management is one of the contents of website availability. Everyone knows that Http has no status request, that is, the last Http request cannot be tracked Related information, but in business, there is a large need to change Http into stateful requests, and Session is generated accordingly. However, in distributed website design, only stateless requests can realize the horizontal expansion of the website (adding or removing application servers), so it is Contradictory to Session, because if Session information is stored in the cache of the website application server, the additional server cannot be used. Therefore, decoupling Session is the key to solving this problem. Here is an introduction to common Sessions on websites management tools.

1. Session replication

##Session replication is the earliest enterprise application system and is commonly used A service cluster Session management mechanism that turns on the Session replication function, which is to synchronize Session objects among several servers in the cluster. JBoss seems to have this function in Java, but .Net is not aware of it yet.

Advantages: Fast reading of Session information and simple implementation.

Disadvantages: When the cluster scale is large, Session replication between servers will occupy server resources and network resources , and eventually the system will be overwhelmed.

2. Session binding

Session binding method is generally provided by soft/hard balancing load servers. This function, for example: the IPhash method of Nginx in the previous article, the load balancing server uses the Hash algorithm to allocate the same IP to the same server, that is, the Session is bound to a specific server, ensuring that the Session can always be obtained on this server. , also known as session stickiness.

Disadvantages: If a server goes down, the Session on this server will no longer exist, and the user requests to switch to An error occurred on other servers because there was no Session.

Detailed explanation of Session distribution

3. Use Cookie to record Session

Recording session information through cookies is a method used by most websites. This method is also a very good and mature solution as long as cookies are not abused. Cookie recording Session is to put some status information on the client, and it must be transmitted to the server for every request.

##Advantages: This method is simple and easy to implement, has high availability, supports horizontal server expansion, and has a mature solution

Disadvantages: Security Sexual issues, Cookies have size limits, and transmitting Cookies with each request will affect performance

Detailed explanation of Session distribution

Detailed explanation of Session distribution. Session server

Session server It is a very good solution to manage Session in this way, because Session is generated for business needs Http state, and distributed website design advocates Http statelessness. In order to meet this design, the Session server will use stateful Session. The information is separated from the stateless application server, and then designed according to the different characteristics of different servers. For example: if we store the Session information in Redis, then there are many good solutions for the cluster configuration and stability settings of Redis. If the Session is stored in Memcache, then the cluster configuration of Memcache, There will also be many mature cases for stability settings. In this way, we simplify some problems. If we use .Net Session alone, we need to understand more deep-seated things in .Net and transform them to ensure their usability and stability. The deeper the things, the more time and experience it takes. If you transfer the Session storage medium to Redis, the Redis cluster solution and management tools are very mature. You only need to configure the configuration to solve the Session problem. Why not do it.

Advantages: High availability, high security, good scalability, high performance, unlimited information size

Detailed explanation of Session distribution

3. .Net Core+Redis+Nginx realizes Session distributed sharing


1. Preliminary preparation & environment

(1)Vs2017 (2).Net Core 1.1 (3) Win 7 (Detailed explanation of Session distribution)ubuntu 16.0Detailed explanation of Session distribution

2、.Net CoreIntroduction

​​​​ With the development of the Internet, in today's Chinese market (not very clear in foreign countries), open source and cross-platform are one of the important indicators to measure the quality of a language and technology. In order to promote .Net open source and cross-platform, Microsoft created .Net Core. .

## For details, see Daniel's article: .Net core and .NET Framework, Mono Let’s talk about my initial feelings about .Net Core:

## 1) .Net Core has not subverted the previous C# syntax

In layman’s terms, I used to speak Chinese (C#), but now I still speak Chinese, but the environment in which I speak has changed.

2) Because .Net Core has just started, API has changed or is missing a lot

In layman’s terms, it means that the speaking environment has changed, and there are many things you have never seen before. You don’t know what official words to use to describe them, because the officials are looking for related words to describe these new things.

3) Leaving from IIS, cross -platform

## 俗 is Microsoft's mother to prevent us from getting to the new environment I am hungry and afraid that I will not know how to survive after leaving the current environment (Windows + IIS). So, he taught us the language (C#), gave us the tools to make money (.Net Core+Kestrel), and said, "Go on, kid, go and work on your own, wait a minute, don't forget to bring this Visa card." (.Net Core SDK), I will send you money regularly.”

# Detailed explanation of Session distribution) NuGet is becoming more and more important

       After several years of development, NuGet has become more and more mature. It is the main method to obtain .Net Core open source components. Through NuGet, you can download various

middleware and components, and it is convenient and fast (except sometimes Disconnected from the Internet, but you can use domestic mirrors), NuGet is like an address book given to us by Microsoft’s mother, and tells us that if you need help in some aspects, you can find your seven aunts and eight aunts through NuGet. help.

3. Topology diagram

Detailed explanation of Session distribution## Based on the successful experience in previous articles , a simple modification, a Windows system and an Ubuntu system in the middle host the .Net Core program. Some people will ask why Windows doesn’t have IIS. What I want to say is that .Net Core implements the principle of going global and is basically separated from IIS. If you want to deploy a .Net Core program on IIS, you need to

install

the same application, and the application pool configured on the site must also be changed to "unmanaged code".

Detailed explanation of Session distribution. Develop .Net Core program using Session

Detailed explanation of Session distribution-1. Create a Web program

## Use Vs2017 to create a .Net Core Web application, and this application does not contain authentication information

Detailed explanation of Session distribution

The creation is as followsDetailed explanation of Session distribution

#Detailed explanation of Session distribution-2、Detailed explanation of Session distribution .

Net Core calls Session

.Net Core uses Session, which requiresQuote After checking the NuGet package related to Session online, I found that the official Session component of .Net Core is similar to a middleware and officially supports Redis.

Note: .Net Core’s Mvc cannot Use Session directly. If you write HttpContext.Session in the program, the following error will appear: Session has not been configured for this application or request.

Detailed explanation of Session distribution

Detailed explanation of Session distribution-2-1、Microsoft.AspNetCore.Session

.Net Core must install Microsoft.AspNetCore.Session to use Session. Its NuGet package installation is as shown below:

Detailed explanation of Session distribution

Detailed explanation of Session distribution-2-2. Modify Startup.cs to make Session available

## ​ Add the highlighted code at the corresponding locationservices.AddSession(); app.UseSession();

<br>

public void ConfigureServices(IServiceCollection services)
 {     // Add framework services.     services.AddMvc();     services.AddSession();
 }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
     loggerFactory.AddConsole(Configuration.GetSection("Logging"));
     loggerFactory.AddDebug();     if (env.IsDevelopment())
     {
          app.UseDeveloperExceptionPage();
          app.UseBrowserLink();
     }     else
     {
          app.UseExceptionHandler("/Home/Error");
     }

     app.UseStaticFiles();     app.UseSession();
     app.UseMvc(routes =>
     {
          routes.MapRoute(
          name: "default",
          template: "{controller=Home}/{action=Index}/{id?}");
     });
}

Detailed explanation of Session distribution-2-3, Session writing and reading

       The reading method of Session is different from .Net. The writing method is as follows, and the Session’s HttpContext.Session.Set String or HttpContext.Session.Set method supports string and Byte array respectively, so complex entities need to be converted into Json Store in Session.

【Session writing method】

<br>

HttpContext.Session.SetString("key", "strValue");

【 Session reading method】

<br>

HttpContext.Session.GetString("key")

Detailed explanation of Session distribution. Change the Session storage medium to Redis

Detailed explanation of Session distribution-1. First configure Redis

For detailed configuration methods, see: Session distributed sharing = Session + Redis + Nginx

<br>

redis-server redis.windows.conf

For detailed configuration, see: Session distributed sharing = Session + Redis + Nginx

##Detailed explanation of Session distribution-2. Install Microsoft.Extensions.Caching.Redis.Core##​ NuGet

Search

Microsoft.Extensions.Caching.Redis.Core and install it. This NuGet package is an extension of Caching, that is, you can replace the Caching storage medium

Detailed explanation of Session distribution

Detailed explanation of Session distribution-3. appsettings.json configures the Redis connection string

     

appsettings.json configures the Redis connection string ( Equivalent to configuring the appsetting node in web.config), note: the adding position must be above Logging, otherwise it cannot be read, add the code as the highlighted part below

<span style="color: #000000">{<br><br></span><span style="background-color: #ffff00"><span style="color: #800000">  "</span><span style="color: #800000">Data</span><span style="color: #800000">"</span>: <span style="color: #800000">"RedisConnection</span><span style="color: #800000">"</span></span><span style="background-color: #ffff00">,<br><span style="color: #800000">"</span><span style="color: #800000">ConnectionStrings</span><span style="color: #800000">"</span></span><span style="background-color: #ffff00">: { <br><span style="color: #800000">    "</span><span style="color: #800000">RedisConnection</span><span style="color: #800000">"</span>: <span style="color: #800000">"</span><span style="color: #800000">192.168.8.138:6379</span><span style="color: #800000">"<br></span></span><span style="line-height: 1.Detailed explanation of Session distribution; background-color: #ffff00">  },</span>
"Logging": {    "IncludeScopes": false,    "LogLevel": {      "Default": "Warning"
    }
  }
}

<br>

Detailed explanation of Session distribution-Detailed explanation of Session distribution. Add a reference to the ConfigureServices method of Startup.cs

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span><span style="color: #000000"> ConfigureServices(IServiceCollection services)
        {            </span><span style="color: #008000">//</span><span style="color: #008000"> Add framework services.</span><span style="color: #000000">            services.AddMvc();<span style="background-color: #ffff00">            services.AddDistributedRedisCache(option </span></span><span style="line-height: 1.Detailed explanation of Session distribution; background-color: #ffff00">=><br></span><span style="line-height: 1.Detailed explanation of Session distribution; background-color: #ffff00">            {       </span>

                   //redis 数据库连接字符串<br>                   option.Configuration = Configuration.GetConnectionString("RedisConnection");<br>                   //redis 实例名<br>                   option.InstanceName = "master";<br>              });<br>              services.AddSession();<br>

<br>

          }

         页面运行HttpContext.Session.GetString("key"),然后用Redis管理工具RedisDesktopManager查询Session是否入库。

Detailed explanation of Session distribution

Detailed explanation of Session distribution-Detailed explanation of Session distribution、发布前指定IP和端口(重要) 

         如果你没有看这个步骤,继续下面发布步骤,等你发布时候,你会发现一个尴尬的问题,就是你用IP访问不了你的网站,用localhost可以访问,.Net Core默认是Detailed explanation of Session distribution000端口,端口占用也会让你的网站访问不了。

         只需要在Program.cs中添加高亮代码即可,细心地人已经看到.UseUrls(new string[] { }) 传入的是个数组,那么这里定义多个网站,当你执行时候dotnet命令时候,多个网站都会启动。

Detailed explanation of Session distribution

<br>

public static void Main(string[] args)
        {            var host = new WebHostBuilder()

                  //增加处,*号表示ip <br>                  .UseUrls(new string[] { "http://*:7201})

                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<startup>()
                .UseApplicationInsights()
                .Build();

            host.Run();
        }</startup>

6、.Net Core 发布

6-1、Windows安装.Net Core发布环境[10.2.107.100]

  1) InstallationWindows Server Hosting (x6Detailed explanation of Session distribution & x86), is equivalent to IIS, please pay attention to the Internet during installation (it seems to be automatically downloaded sdk, I haven’t studied it carefully).

Detailed explanation of Session distribution

             2) Enter the dotnet command to verify. If "'dotnet' is not an internal or external command" please find "C :\Program Files\dotnet" folder, use cmd to call dotnet.exe to run, or add the system environment variable (the cmd command in window can save .exe when writing commands , that is, the command dotnet is dotnet.exe)

Detailed explanation of Session distribution

##【】 1]

In Win7, I prompt an error: Failed to load the dll from [C: \ Program Files \ Host \ fxr \ 1.0 .1\hostfxr.dll], HRESULT: 0x800700Detailed explanation of Session distribution7

Detailed explanation of Session distribution

            Solution:

## need to be installed patch: kb2Detailed explanation of Session distribution33623

##is as follows:

##     

https://support.microsoft.com/en-us/kb/2Detailed explanation of Session distribution33623

【Pit 2】##                                                                                                  This article is mainly developed using .net Core 1.1.1. The following two screenshots are error messages

Detailed explanation of Session distribution6-2. Ubuntu installation.Net Core release environment<br>[10.2.107.Detailed explanation of Session distribution6]<br>

Ubuntu Installation of .Net Core

The official instructions are very detailed. Just follow them. Don’t conflict with the

Linux system. If so, don’t use it. Net Core, if you don’t know the relationship between Ubuntu and Linux, please go to Baidu. Finally, verify whether the dotnet command can be used.

Detailed explanation of Session distribution

##6-3. Publishing website

Detailed explanation of Session distribution

          

Right-click on the project- >Publish…

       点击发布按钮,生成的文件如下(SessionTest为应用程序名)

Detailed explanation of Session distribution

        好了,有了这些文件,我们只需要把这些文件扔到服务器上就成了,但是怎么启动呢?通过查询,网上说只要用dotnet命令就成。继续实践…

        说明:我的项目叫做Detailed explanation of Session distribution生成了Detailed explanation of Session distribution这个为主要的dll,也是程序的入口。

        大家都知道.Net Core是跨平台的,不同系统的服务器环境配置好了,网上查询说是使用dotnet命令启动网站,那么可以推断出几个平台的dotnet命令是一样的。

6-3-1、Windows启动.Net Core网站[10.2.107.100:7201]

         启动.Net Core网站的命令很简单,安装好发布环境的应用程序,C:\Program Files\dotnet目录如下(如果dotnet命令不能用,可以直接调用dotnet.exe这个应用程序。)

Detailed explanation of Session distribution

         将生成好的网站复制到服务器上

Detailed explanation of Session distribution

 cmd命令找到PublishOutput

<br>

cd C:\PublishOutput

Detailed explanation of Session distribution

dotnet运行网站命令

dotnet SessionTest.dll

成功以后(之后再编译运行,会提示下面截图)

Detailed explanation of Session distribution

访问http://10.2.107.100:7201/(如果一台机子有多个网卡多个IP,其他IP的7201端口也是个独立网站)

Detailed explanation of Session distribution

 

6-3-2、Ubuntu启动.Net Core网站[10.2.107.Detailed explanation of Session distribution6:7201]

想办法将发布的程序复制到Ubuntu上面去,我测试使用的VBox虚拟机。

具体方法传送门:virtualbox中ubuntu和windows共享文件夹设置

dotnet SessionTest.dll

Detailed explanation of Session distribution

访问http://10.2.107.Detailed explanation of Session distribution6:7201/

Detailed explanation of Session distribution

7、Nginx配置

7-1、网站端口修改

        nginx.conf配置修改

Detailed explanation of Session distribution

        listen   80; 改成 listen   81; 因为一般都被80都被使用。

<br>

server {
        listen       81;
        ……
}

7-2、增加负载均衡

  nginx.conf中添加upstream节点

upstream Jq_one { <br>      server 10.2.107.100:7201; <br>       server 10.2.107.Detailed explanation of Session distribution6:7201;

} server {
.....
}

 

7-3、location节点修改

<br>

location / {
            root   html;
            index  index.aspx index.html index.htm;            #其中jq_one 对应着upstream设置的集群名称
            proxy_pass         http://Jq_one;             #设置主机头和客户端真实地址,以便服务器获取客户端真实IP
            proxy_set_header   Host             $host; 
            proxy_set_header   X-Real-IP        $remote_addr; 
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

7-Detailed explanation of Session distribution、Nginx启动命令

        C:\server\nginx-1.0.2>start nginx

        或

        C:\server\nginx-1.0.2>nginx.exe

7-Detailed explanation of Session distribution、Nginx重新载入命令

      C:\server\nginx-1.0.2>nginx.exe -s reload

 

四、黎明前的黑暗-MachineKey


 

      本以为做了上述准备和相关代码编写,就能够实现Session共享了,结果我想的太简单了,应用程序发布后并不能实现Session共享,难道分布式共享下Session需要特殊处理?.Net我是怎么实现的,它们的方法应该方法类似。我突然想到了MachineKey这个东西,之前在.Net版本分布式共享时候需要添加这个东西,评论也有人问我什么要加MachineKey。后来只能搜索.Net Core Machinekey关键词,找到了以下几篇文章做参考。

      搭建分布式 ASP.NET Core Web

      ASP.NET Core 数据保护(Data Protection)

      坎坷路:ASP.NET Core 1.0 Identity 身份验证(中集)

      net core 1.0 实现负载多服务器单点登录

      此问题属于数据安全问题,微软在开发.Net Core中延续了之前的设计,采用数据保护(Data Protection)方式对一些内部数据进行加密解密设计,如:Session、Cookie等(远不止这些)。这样可以保证数据的真实性、完整性、机密性、隔离性。数据安全必然离不开加解密算法,大家想一下之前.Net的WebFrom中的ViewState,它最终解析到Html页面是个hidden标签里面有一串很复杂的字符串,这个字符串是被数据保护(Data Protection)机制加密过的。Session也一样,大家可以看看Session存到Redis中啥样,见下图:

Detailed explanation of Session distribution

       数据保护(Data Protection)有个特性是隔离性,大家可以想象一下,数据保护核心是加密解密,常见的加密方式有对称加密和非对称加密,上一篇做分布式共享时候,两台机子拷贝了同样的MahcineKey,那么他的内部加密猜测好像是对称加密,MachineKey直译中文为“机器钥匙”在联想隔离性,那么可以推断出来不同机子密钥是不同的,那么MachineKey的作用是统一不同机子的密钥。(吐血中…….这个只是个猜测,详细原理请参考专业文章)

1、提取.Net Core的MachineKey

        .Net Core的MachineKey存储是以key-xxxx-xxxx-xxxx-xxxx.xml的形式存储的,那如何提取这个xml信息呢?

       Startup.cs的ConfigureServices添加下图高亮代码

<br>

public void ConfigureServices(IServiceCollection services)
        {

              //抽取key-xxxxx.xml <br>

            services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(@"D:\XML"));
            services.AddSession();
            services.AddDistributedRedisCache(option =>
            {                //redis 数据库连接字符串
                option.Configuration = Configuration.GetConnectionString("RedisConnection");                //redis 实例名
                option.InstanceName = "master";
            });
            services.AddMvc();
        }

       查看D:\Xml里的xml文件

Detailed explanation of Session distributionDetailed explanation of Session distribution

 

2、重写IXmlRepository接口固定Key

       在项目中添加CustomXmlRepository.cs类,其中keyContent中填写key.xml内容,注意:里面的几个时间(现在还不能确定expirationDate对项目是否有影响),有人问我KeyContent能否从文件里读,回答是可以,但是ubuntu的文件路径保准不是Windows的d:\之类的,需要使用Linux的写法,所以干脆字符串来的快。

<br>

using Microsoft.AspNetCore.DataProtection.Repositories;using Microsoft.AspNetCore.Http;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;using System.Xml.Linq;namespace SessionTest
{    public class CustomXmlRepository : IXmlRepository
    {        private readonly string keyContent =@"<?xml  version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?>
<key explanation of session distribution38d-9eadetailed distribution-detailed distributiondetailed distributionfb-a690-detailed distribution38c8d788619>
  <creationdate>2017-0Detailed explanation of Session distribution-27T06:1Detailed explanation of Session distribution:07.219Detailed explanation of Session distribution692Z</creationdate>
  <activationdate>2017-0Detailed explanation of Session distribution-27T06:1Detailed explanation of Session distribution:07.18Detailed explanation of Session distributionDetailed explanation of Session distribution6Detailed explanation of Session distribution7Z</activationdate>
  <expirationdate>2017-07-26T06:1Detailed explanation of Session distribution:07.18Detailed explanation of Session distributionDetailed explanation of Session distribution6Detailed explanation of Session distribution7Z</expirationdate>
  <descriptor>
    <descriptor>
      <encryption explanation of session distribution6_cbc></encryption>
      <validation explanation of session distribution6></validation>
      <masterkey explanation of session distribution:requiresencryption="'true' xmlns:pDetailed" distribution="'http://schemas.asp.net/201Detailed">
        <!-- Warning: the key below is in an unencrypted form. -->
      <value>HOzDetailed explanation of Session distribution8FE6STtDHlMo2ZONoPgPTOOjRPikRWXmHOwNDSDetailed explanation of Session distributiono6NPbDetailed explanation of Session distributionhlgl/DxXUhat66soovBUFy1APXCQDetailed explanation of Session distributionz30DDPyw==</value>
      </masterkey>
    </descriptor>
  </descriptor>
</key>";         
        public virtual IReadOnlyCollection<xelement> GetAllElements()
        {            return GetAllElementsCore().ToList().AsReadOnly();
        }        private IEnumerable<xelement> GetAllElementsCore()
        {            yield return XElement.Parse(keyContent);
        }        public virtual void StoreElement(XElement element, string friendlyName)
        {            if (element == null)
            {                throw new ArgumentNullException(nameof(element));
            }
            StoreElementCore(element, friendlyName);
        }        private void StoreElementCore(XElement element, string filename)
        {
        }
    }
}</xelement></xelement>

修改Startup.cs文件中的ConfigureServices方法加载自定义的CustomXmlRepository类

<br>

public void ConfigureServices(IServiceCollection services)
        {            ////抽取key-xxxxx.xml
            //services.AddDataProtection()            //        .PersistKeysToFileSystem(new DirectoryInfo(@"D:\XML"));            services.AddSingleton<ixmlrepository>();</ixmlrepository>

              services.AddDataProtection(configure =>

            {
                configure.ApplicationDiscriminator = "newP.Web";
            });

            services.AddSession();
            services.AddDistributedRedisCache(option =>
            {                //redis 数据库连接字符串
                option.Configuration = Configuration.GetConnectionString("RedisConnection");                //redis 实例名
                option.InstanceName = "master";
            });

            services.AddMvc();

        }

五、实现效果演示


         演示效果说明

         本机127.0.0.1也为10.2.107.100,因为电脑性能有限,没有弄windows虚拟机,只弄了10.2.107.Detailed explanation of Session distribution6这台Linux虚拟机。

         MachineKey的这个实现思路也可以用到.Net Core的身份验证上。

         UNC文件也可以实现Session共享方式

         原理就是Windows和Linux通过文件共享和挂载的方式Key.xml共享一个文件,但是总觉得有点怪怪的,共享文件会不会被别人恶意篡改,所以最后采用重写的方式实现。

         对UNC方式感兴趣的请看:搭建分布式 ASP.NET Core Web

 

 

Detailed explanation of Session distribution 6. Postscript & Thoughts


## I hope that through this article , let everyone have a simple understanding of the usability of the website, and understand the advantages of storing Session in Redis. This article introduces the tip of the iceberg in website usability content, and there is still a lot of knowledge that we need to learn and accumulate.

.Net Core version of Session distributed sharing gives us a preliminary understanding of .Net Core. .Net Core’s high performance, cross-platform, and open source have changed many people’s minds. My opinion on .Net, but .Net Core still has a long way to go in the Chinese market. I think .Net Core is not a silver bullet to reverse the .Net language’s market share in China. The real silver bullet may be .Neter like us who write programs every day. Even if Microsoft promotes .Net Core a lot and success stories are everywhere, if we don’t learn and understand new knowledge, we will eventually be eliminated. Language is just a tool. Only through continuous learning and hard work, digesting, absorbing and finally sharing knowledge with others can we gain the greatest gain. When we are confused at the crossroads, why not learn new knowledge and methods to improve our own experience and experience. I often tell others that the most important thing in the first few years of work is not knowledge, but the style of doing things and the belief in perseverance towards the goal. As the saying goes, "It's easy to change the situation, but it's hard to change the nature." If you have a bad working attitude and method, It has become your work habit. Even if you change the language, job or even industry, it will have a great impact on your career development. Good habits must be persisted. Some things can be persisted for one day or two days, but if you persist for more than three months, it becomes an impossible task, let alone a few years. "If you don't accumulate small steps, you can't reach a thousand miles." Only by persisting in tempering myself every day can I grow, because I know that I am not a genius and it takes hard work to grow.

“Be a down-to-earth person and do things conscientiously.” I firmly believe that my efforts will be rewarded, but I have not seized the opportunity yet. Finally, I would like to pay tribute to those who are working hard on the front line to develop using .Net Core.

## The above summary is my rich chicken soup for the soul

, but when can I get rid of my procrastination outside of work?

, this article has been delayed Procrastination, the paper keeps procrastinating, learning English procrastinates, there are still many things to do, but it keeps procrastinating, what a tragedy. . . Suddenly I realized that Yali Mountain is huge and bad habits are hard to change! Please take this as a warning! Of course, don’t be a workaholic. Good health is more important and you can spend more time with your family. Detailed explanation of Session distributionDetailed explanation of Session distributionDetailed explanation of Session distribution##​​​​ understanding.

7. Reference article

#ASP.NET Core uses Redis and Protobuf for Session caching

.Net Core Session uses

Asp.net Core uses Redis to store Session## Using Sessions and HttpContext in ASP.NET Core and MVC Coreexplanation of Session distribution>

The relationship between .NET Core, .NET Framework and Mono

ubuntu in virtualbox Shared folder settings with windows

Build a distributed ASP.NET Core Web

ASP.NET Core Data Protection (Data Protection)

Bumpy Road: ASP.NET Core 1.0 Identity Authentication (CIMC)

Net core 1.0 realizes load multi-server single sign-on

The above is the detailed content of Detailed explanation of Session distribution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn