Multi-site Session sharing

Source: Internet
Author: User
After the website is revised, users must use the Unified Identity Authentication System of Southeast University to share sessions among multiple asp.net applications.
There are too many materials to check, and it is not feasible. It may be feasible (including the official Microsoft method) to change the application itself a lot... too much trouble! Very unhappy!
Finally, find a solution... but it is estimated that Microsoft will be unhappy.

General idea:
You can use SqlServer to store sessions and analyze the structure, principles, and procedures of database tables. You can obtain the method for storing sessions in SqlServer:
Table Structure:


ASPStateTempApplications table store Application Id and name
ASPStateTempSessions table stores specific Session values

Different applications will register different data in ASPStateTempApplications to have different sessions in ASPStateTempSessions. To achieve Session sharing, you can use the method of spoofing SqlServer:In some way, make different applications use the same App when accessing the database!For this purpose, the Code for analyzing the stored procedure [dbo]. [TempGetAppID] is as follows: Code
1 alter procedure [dbo]. [TempGetAppID]
2 @ appName tAppName,
3 @ appId int OUTPUT
4
5 SET @ appName = LOWER (@ appName)
6 SET @ appId = NULL
7
8 SELECT @ appId = AppId
9 FROM [Herald. Session]. dbo. ASPStateTempApplications
10 WHERE AppName = @ appName
11
12 IF @ appId IS NULL BEGIN
13 BEGIN TRAN
14
15 SELECT @ appId = AppId
16 FROM [Herald. Session]. dbo. ASPStateTempApplications WITH (TABLOCKX)
17 WHERE AppName = @ appName
18
19 IF @ appId IS NULL
20 BEGIN
21 EXEC GetHashCode @ appName, @ appId OUTPUT
22
23 INSERT [Herald. Session]. dbo. ASPStateTempApplications
24 VALUES
25 (@ appId, @ appName)
26
27 IF @ ERROR = 2627
28 BEGIN
29 DECLARE @ dupApp tAppName
30
31 SELECT @ dupApp = RTRIM (AppName)
32 FROM [Herald. Session]. dbo. ASPStateTempApplications
33 WHERE AppId = @ appId
34
35 RAISERROR ('SQL session state fatal error: hash-code collision between applications' % s' and '% s ''. please rename the 1st application to resolve the problem. ',
36 18, 1, @ appName, @ dupApp)
37 END
38 END
39
40 COMMIT
41 END
42
43 RETURN 0

We can see that the input parameter is AppName, And the AppName is used to obtain the AppId. If it does not exist, this record is inserted in the ASPStateTempApplications table. Here, the AppName parameter is different for different applications, of course, we can make minor changes here... note that we can change SET @ appName = LOWER (@ appName) to SET @ appName = 'Everything you want ^_^ 'on the first line'
Okay (I don't know if Microsoft will be unhappy with doing so ...), as a result, it is best to restart IIS to clear the residual sessions without modifying the old program itself (configure the web. except for config), implements Session sharing... in the future, all users who use this database as Session storage can share the Session...

Other configurations are described as follows:

Configure the web. config section:

<SessionState mode = "SQLServer" sqlConnectionString = "data source = [Server]; initial catalog = [DataBase]; user id = [UserName]; password = [Password] "allowCustomSqlDatabase =" true "timeout =" 120 "/>

Configure SQLServer: Aspnet_regsql.exe-sstype c-ssadd-d [DataBase]-U [UserName]-P [Password]-S [Server]

 
Modify [dbo]. [TempGetAppID]: Set @ appName to a value and save the modification.

Clear Session, restart IIS, KO!

PS: This method is actually quite a Bug. If you study the database stored procedure or use some method to customize the appName, you may be able to implement more functions... for future research...

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.