ASP. NET implements multi-domain name multi-site shared session Value

Source: Internet
Author: User

Advertisement: open-source natural framework of golden oceanCommunityQQ group: 82598514. I hope you can provide more support.

ASP. NET implements multi-domain name multi-site shared session Value
1. Implementation function: You can set which sites can share the session value, so as to prevent others from using this to access

To implement this function, you must put the session value in the database. First, register

The name is as follows: aspnet_regsql.exe-s [database service address]-e-ssadd. For the specific format, refer /?

After successful addition, we need to make simple modifications to the stored procedure generated by ASP. NET,
Open Asp.net and find the stored procedure "tempgetappid" for the database "aspstate" created for us"
Then modify the stored procedure as follows:

 Use   [  Aspstate  ] 
Go
/* * *** Object: storedprocedure [DBO]. [tempgetappid] script Date: 11/21/2011 16:15:27 ***** */
Set Ansi_nulls On
Go
Set Quoted_identifier Off
Go

Alter Procedure [ DBO ] .[ Tempgetappid ]
@ Appname Tappname,
@ Appid Int Output
As
Set @ Appname = Lower ( @ Appname )
Set @ Appid = Null
Set @ Appid = 640732509 -- This is what I wrote when I tested it myself. You can query the site appid through the aspstatetempapplications in the system database tempdb. Remember that only when the seeion configuration of the website is
 The database can be queried only when the session value is saved once.  
/*
-- Select @ appid = appid
-- From [tempdb]. DBO. aspstatetempapplications
-- Where appname = @ appname
The above annotation method is automatically generated by the original Asp.net
*/

If @ Appid Is Null Begin
Begin Tran

Select @ Appid = Appid
From [ Tempdb ] . DBO. aspstatetempapplicationsWith (Tablockx)
Where Appname = @ Appname

If @ Appid Is Null
Begin
Exec Gethashcode @ Appname , @ Appid Output

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

This can be shared, but we have to solve the problem of replacing the seeionid of the client. We can add a processProgramTo use the sessionidmanager class for processing,
I will not write the instance, and I will write a replacement method for the value.

Sessionidmanager sessionid =NewSessionidmanager ();
BoolA;
BoolB;
Sessionid. savesessionid (This. Context,"Here is seeionid",OutA,OutB );

Last modified configuration file
Add <sessionstate mode = "sqlserver" sqlconnectionstring = "Data Source = data connection; user id = sa; Password = 123456;"> </sessionstate> to the system. Web node.

Okay. You can try it.

 

Related Article

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.