简体   繁体   中英

Access ASP.NET Session in SQL Server mode across multiple applications

I'm trying to access the shared Sessions stored in SQL Server from multiple applications in different servers.

I already read this Sharing sessions across applications using the ASP.NET Session State Service but I had no luck.

Here's how I set up the web.config of both applications:

<sessionState 
    mode="SQLServer"
    allowCustomSqlDatabase="true"
    sqlConnectionString="Application Name=MyAppName; Data Source=MyDataSource; Initial Catalog=MyDBName; User Id=MyUser; Password=MyPassword"
    cookieless="false" 
    timeout="250" 
/>

And here is the machine key I set up in both config files:

<machineKey validationKey="key1" decryptionKey="key2" validation="SHA1" decryption="AES" />

Both the applications can read and write the database.

I also tweaked the TempGetAppID stored procedure to overcome the application name limitations. In such way my SessionID s share the same suffix.

That said, I still have 2 different records in the ASPStateTempSessions table, with different SessionID s.

Here's an example:

3nn53mh3j0vf3mrravuda11o9c8d4bee
oljchatkqzcje1ae1b3n2pst9c8d4bee

Any ideas would be appreciated!

EDIT 1

I tried with both Chrome and IE on a single tab.

I found the issue.

The problem was that I was (stupidly) trying to share the session between two applications with different host names. In such way, the SessionID was correctly stored in SQL Server but, while one of the applications was able to generate and store the SessionID in the cookie, the other application could not read such cookie because of the different domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM