Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
964 views
in Technique[技术] by (71.8m points)

best way to share "session state" type data between two .net applications

we have a web application that, started out small, any new features that were added on, were just made as part of the same project, however now we would like to create new projects for these said addons...

we created a new project, it inharits the global.asax of the main project, and also accesses the web.config of the main project just fine, however, in the global asax code there's session checking for data integrity, to see if the user is logged in.. this is where we are getting issues.. the user is logged in, but the site errors out stating that they arnt logged in, because the addon project cannot access the session user id that is set by the main project.

currently we are not using a session state server, or sql state server, and we would like to avoid it to avoid any headaches for some of the older code.

also we dont want to go the route of mutexes.. want to stay away from windows coding if we can as well...

site outline of what happens with the session: user logs in with asp code ( .net 1.1 code) user is authenticated and successfully logged in, sends a guid for that user to a database, the main project( .net 2.0 code) grabs that guid, grabs the users data and stores the user id in the session. any page that requires knowing who the user is, gets it from the session("userid")

so: we create another project that inheirits the global.asax, can access the web.config - DONE!

what we want to do on top of this: have this new project contain a page (addon feature from the main project) have this page access the session("userid") that is set from the main project. - NOT SURE HOW TO DO THIS...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would prefix my suggestion by saying that the best way to keep complexity to a minimum would be to use a state server. This is a problem they are designed to solve.

That having been said...

Since the two applications have to run in different processes (as they are in different runtime versions), they cannot directly share the data.

One option could be to use Web Services or Remoting. You could have a CustomSession object which stores all a session's data, and identify each one by a Guid. You could track all your existing sessions created in Application A by Guid-CustomSession, and pass the Guid via querystring to Application B. Application B can query Application A with the Guid, either via Web Service or Remoting, and get the corresponding CustomSession object back. You could do the same in reverse as well.

The only issue here is you have to make sure the Guid is always provided in the URL when moving from a page in App A to a page in App B or vice-versa. The application can always check if session does not exist, to fall back to using the Guid to see if the other app has a session.

Do beware that some .NET data structures (not many) are serialized differently between .NET 1.1 and 2.0, so when sharing the objects over remoting or web services, you may need to account for that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...