Multi-site shared session Status of sessions in sqlserver mode in Asp.net

Source: Internet
Author: User

Record the process first:

1. Modify configuration file

<System. Web>
<! -- Enable cross-site access to share sessions -->
<Httpcookies domain = "csdn. Net"/>
<! -- Set the session mode to sqlserver -->
<Sessionstate mode = "sqlserver" sqlconnectionstring = "Data Source = 127.0.0.1; user id = aspstate; Password = aspstate;" timeout = "60"/>
</System. Web>
2. Modify the tempgetappid Stored Procedure of aspstate to keep the same appid for different sites.

This is the only way to customize the appname.

/**//*

Obtain appid

Modify the process to generate only one appid

*/
Create procedure DBO. tempgetappid
@ Appname tappname,
@ Appid int output
As

Set @ appname = lower (@ appname)
Set @ appid = NULL

-- Query the appid corresponding to the appname
-- Modified at the time so that every appid is the same.
Select top 1 @ appid = appid
From [tempdb]. DBO. aspstatetempapplications
-- Where appname = @ appname

-- If no appid is found
If @ appid is null
Begin
Begin tran
-- Lock mode Query
Select @ appid = appid
-- Select top 1 @ appid = appid
From [tempdb]. DBO. aspstatetempapplications with (tablockx)
Where appname = @ appname

-- If no appid is found
If @ appid is null
Begin
-- Obtain the hashcode of appname
Exec gethashcode @ appname, @ appid output

-- Insert a new appid
Insert [tempdb]. DBO. aspstatetempapplications
Values
(@ Appid, @ appname)

If @ error = 2627
Begin
Declare @ dupapp tappname

Select @ dupapp = rtrim (appname)
From [tempdb]. DBO. aspstatetempapplications
Where appid = @ appid

Raiserror ('SQL session state fatal error: hash-code collision between applications' % s' and '% s ''. please rename the 1st application to resolve the problem. ',
18, 1, @ appname, @ dupapp)
End
End
Commit
End

Return 0
Go

 

There are many ways on the Internet, but they are not required by my environment.

1. Modify site IIS metadata
The IIS Site has different IDs (/lm/w3svc/1009009583/root, ID is 1009009583, usually 1 ), this method is suitable for site clusters with multiple servers (if the site ID is changed to the same on the same server, site disorder occurs ).
For step information about how to resolve different application paths between servers, see in http://support.microsoft.com/default.aspx? Ln = en-CN in the Microsoft Knowledge Base Article 325056 "PRB: session state is lost in Web farm if you use sqlserver or StateServer session mode" (PRB: if you use sqlserver or StateServer session mode, the session status will be lost in the network ).

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.