Share via


Sharing Session across multiple web applications

Question

Monday, March 17, 2008 7:28 PM

Hi All,

I am trying to come up with a way to let all the web applications under a single website share the same session-scope.  My motivation for doing this is due to the way our company's web-based information system has developed over the years - it is basically an aggregation of several different web-apps which communicate with one another.  Currently there are various techniques used to achieve this inter-application state management (ajax calls, url params), however it would be much better if the different apps could just share the same sessions. Some basic specs for the environment: ASP.NET 2.0,  SQLServer state management,  all web-apps are under the same website. The basic structure in IIS is as follows:

 IIS
    RootWebSite (www.oursite.com)
        - webapp one
        - webapp two
        - webapp three

 
My first attempt to achieve this was to implement a custom SessionIDManager class, in the hopes that it was the CreateSessionID method of this class that had complete control over the session id.  Of course, this was not the case - when I look in the ASPState db, the session ids are postfixed with the web-apps' appid.   

Anybody know of a way to achieve this without resorting to implementing a completely custom session state management system?

Thanks for any help!

JS 

 
 

All replies (12)

Tuesday, March 18, 2008 1:17 PM âś…Answered

Please see this url for what is application name and where you use it.

http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx

Also, you can save session into MS SQL database, so another project can use the session

Look this url for how to share session between class asp and asp.net and also how it save into database

http://msdn.microsoft.com/en-us/library/aa479313.aspx


Monday, March 17, 2008 8:24 PM

Hi,

What you really need is to create your own SessionStateStoreProvider. Take a look at SqlSessionStateStore for inspiration.


Tuesday, March 18, 2008 1:30 AM

 

How about use a same application name in your web.config, and in database, you will get same appid?


Tuesday, March 18, 2008 9:04 AM

 Please forgive my ignorance, but where can you specify the application name in the web.config? And, when you say "...and in database" do you mean to manually alter the app name in the ASPState db?

Thanks for your help! 


Tuesday, March 18, 2008 6:05 PM

Nice! This looks like just the thing - can't wait to test it out. I'll be sure to mark your response as the answer once I validate.

Cheers!!! 


Tuesday, March 18, 2008 6:09 PM

 

I use it for share session between asp, asp.net 1.1 and asp.net 2.0 and all is working for me, but did not try asp.net 3.5


Wednesday, March 19, 2008 2:07 AM

Tony,  could I trouble you for a sample snippet of the sessionState element from a web.config that uses this.  Also, am I correct in assuming this technique requires using the aspnetdb database as opposed to the older ASPState?

Thanks Again!

 


Wednesday, March 19, 2008 1:04 PM

Not required, the aspnetdb is optional, because you know asp, asp.net 1.1 don't have it .


Wednesday, March 19, 2008 6:48 PM

Hi Again, still fumbling with this...I now see that the ASPState database co-exists with the ASPNETDB database, however I am still at a loss trying to find the specs on the provider element for the built-in SQLSessionStateStore provider.  The two links Tony sent earlier did not really answer the question - the first did explain the provider model, but was pretty specific to membership and roles, and the second discussed implementing a custom session provider.  Tony, if I understand you correctly, there is a way to configure the built-in SQL Session State provider so I will not have to write a custom session store provider.  I would be grateful if you could post a snippet of a web.config file that shows how to do this configuration.

Thanks Again!

Jon 


Wednesday, March 19, 2008 6:54 PM

Hey Nuno, thanks for your post, somehow I didn't notice it previously!  I'm going to have a look at the SessionStateStoreProvider, hopefully the source for it is available. could then just be a matter of replacing the way it postfixes the session id in the database. 

Cheers,

Jon (From Victoria, BC, Canada - North America's West Coast!) 


Wednesday, March 19, 2008 8:30 PM

 

Hi Jon

 

Did you make the demo working on your local machine, I think you need to do so, just ignor the first url, make the share session working and get feeling how it works is most important.


Tuesday, January 13, 2009 4:46 AM

You can use session insted of query perameters.

If these two projects are in different virtual directories run as different servers, it's not possible directly share the session in different server process.(assume session attribute is Inproc mode)

To share session in different application, you should use a state server, for example: http://blogs.msdn.com/toddca/archive/2007/01/25/sharing-asp-net-session-state-across-applications.aspx