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

后端 未结 6 2047
执念已碎
执念已碎 2020-12-16 07:33

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 p

6条回答
  •  青春惊慌失措
    2020-12-16 08:17

    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.

提交回复
热议问题