Why can't I share Session state between 2 web apps with StateServer? What am I missing?

前端 未结 4 394
情深已故
情深已故 2020-12-10 14:07

I\'m having trouble getting 2 identical ASP.NET MVC applications to share the same Session using a Session StateServer. The reason I\'m trying to do this is we will eventual

4条回答
  •  暖寄归人
    2020-12-10 14:48

    Update: Here is a previous post I answered on this same topic Sharing sessions across applications using the ASP.NET Session State Service

    As already pointed out, Session data is scoped to the application. That is the Application you create in IIS. So two applications with the same session id will not be sharing the same session because of the application scoping.

    As an alternative idea that might or might not be feasible for you. You can create a root application and have the code for D:\App1 and D:\App2 in two subfolders.

    d:\Root
      web.config
      \App1
         default.aspx
         ...
      \App2
         default.aspx
         ...
    

    Then in IIS you create an Application pointing to d:\Root.

    You can also create an Application in IIS and then under the Application you create two virtual directories, one pointing to D:\App1 and the other to D:\App2, then they can also share a single web.config at the Application level. It is critical that the two virtual directories are just virtual and not created as Applications.

    So you harddisk layout might look something like this

    D:\Root
      web.config
    
    D:\App1
      default.aspx
      ...
    
    D:\App2
      default.aspx
      ...
    

    Create the root application pointing to D:\Root and then under the application create the two virtual directories App1 pointing to D:\App1 and App2 pointing to D:\App2.

    The effect in both cases is that you actually have one application split into two sections, both in the same Session scope therefore the code for both can share the same session data.

提交回复
热议问题