Requirements:
The company assigned a task. The previous website was a server. because there were too many users and the load was too high, the boss asked to add another server. Add and commit. It should be different from Dev.
Relationship. We should not have met source. However, some data on the website was stored in the session. You should understand the sessino mechanism (your own understanding): when a user accesses the server, a sessionid, httpcontext, will be left in the cookie. current. request. cookies ["ASP. net_sessionid "]. the value can be obtained, and the server will match the data on the server side according to this sessionid. Simply put, your sessionid is used to retrieve the data stored on the server side, similar to key: Word. When a client accesses a server, the data stored in the session is stored on the server. If I add a server, the data of this session will be shared, allow me to access both machines at the same time. In this way, when a user accesses the server, the data in sesson will not be lost when I switch the server machine.
My problems:
I searched on the Internet about the session sharing method, there are a lot of http://www.cnblogs.com/xinhaijulan/archive/2010/08/21/1805116.html, I chose a sqlserver sharing sessin method.
First, you have to create this sqlserver database. CMD command. C: \ windows \ microsoft. Net \ framework \ v2.0.50727> aspnet_regsql.exe-s jpmsnmdb05t-e-d awbuisession-ssadd-sstype C
The command does not understand the link in my article. Very simple.
Then, enter <system. Web>
<machineKeyvalidationKey="1234567890123456789012345678901234567890AAAAAAAAAA"decryptionKey="123456789012345678901234567890123456789012345678"validation="SHA1"decryption="Auto"/>
<sessionStatemode="SQLServer"sqlConnectionString="server=jpmsnmdb05t; database=AWBUISession;Trusted_Connection=Yes; Persist Security Info=False;"allowCustomSqlDatabase="true"cookieless="false"timeout="100"/>
In this step, if you set session ["name"] = "value" in the code, your information will be saved in the session table in the database created by sqlserver.
I set it like this: Obtain the sessionid from the client, and then query the sessionid In the table based on the sessionid. The retrieved data can be decompiled. If you do not know how to read my attachments, I wrote a user to log on to the test system.
I encountered a problem, that is, I would not establish a test environment. There are only two machines. You must remember that sessionid is cookie information, so the sessionid of different domains (that is, URLs) is different, so if you want to create multiple servers to share a session, you must create an identical domain. In this way, you can access that server as you like. For example, when a user logs on to the first server, the server switches to the second server, the user does not know. the user is still visiting the page. The system must check whether the user has logged on. Otherwise, the user must log on. Well, you have to check the information in the session, get information based on sessionid? If the domain is different, your sessionid is different. Now your sessionid is no longer the previous one. You must be in love with your sessionid for logging on to the first server. If you set the same domain, well, no matter how many machines you access and your sessionid is one, it is not a small case to retrieve user information. Okay. How to create the same domian:
Set the local host. Where is the local host path? I asked my colleagues, and I am not very clear about it. c: \ windows \ system32 \ drivers \ etc
You know the IP address of your server. Then you only need to modify your host file and view
172.23.126.137 sessiontest # source server
10.168.109.120 sessiontest # X client host
This is what I added. Two servers, the same domain: sessiontest
Since the port number set when I publish the system to IIS on the server is 8078, I only need to access http: // sessiontest: 8078/locally.
Manually turn on/off the site in IIS to switch the server.
This makes the test environment better.
There is an unsolved problem,If there are readers involved, you can also talk about it. There is no problem in running my vs locally and accessing the page,
If I put the system on the server, I found that when I took the session information, there was only one entry in the session database table that met the search criteria on the page, but there were two entries, the two sessionids are the same as those of httpcontext. current. request. cookies ["ASP. net_sessionid "]. value is the same. The value of httpcontext. Current. Request. Cookies ["ASP. net_sessionid"]. value is different from the sessionid in the aspstatetempsessions table. My httpcontext. Current. Request. Cookies ["ASP. net_sessionid"]. value is only half of the sessionid in the aspstatetempsessions table. Look,
Httpcontext. Current. Request. Cookies ["ASP. net_sessionid"]. Value: X0if3uuddqmpl4451jberf2h
Sessionid in the aspstatetempsessions table: X0if3uuddqmpl4451jberf2h077b2520
If my test code is needed, reply to me and tell me your mailbox that my test system is a user login.
If you have any questions, please reply in time.
If you have any questions, please share them with me.