开发者

IIS, Session State and Virtual Directories

I've created a web site with ASP.NET 2.0 and I'm using a session variable to determine if a user has filled out an age verification form. Everything works as expected (I can read the session variable on all pages) until a user goes to a virtual directory. When they do so, the page can't read the session variable.

After much research, I've so far done the following.

  1. Turn on the ASP.NET State Service

  2. Added a sessionState node to my web.config files, changing the mode to StateServer (for the web site and virtual directory).

    <sessionState mode="StateServer" cookieless="false" timeout="20" stateConnectionString="tcpip=127.0.0.1:42424" />

  3. Generated a new machineKey an开发者_运维问答d added it to both the site and the virtual directory...

    <machineKey

    validationKey="...128..."

    decryptionKey="...64..." validation="SHA1" decryption="AES" />

  4. Created a new application pool and made sure both the web site and it's virtual directory are using the same application pool.

If I write out the session id <%= Session.SessionId %> it is the same on pages in and out of the virtual directory (it's the same throughout the site). I just can't get that session variable! Does anyone know what else I can try to get this to work??

Thanks.


Different virtual directory = different application and applications don't share session data between them. Perhaps a redesign of your applications to avoid this?

Here is a possible solution to sharing session data between ASP.NET applications.

Passing session data between ASP.NET Applications


From everything I can tell, it's not possible to do what I wanted to do. What's worse, I decided to use cookies instead of session variables, thinking that since cookies are created and maintained by the client and based on the domain, that would work. Unfortunately, somehow when created with C#/ASP.NET even cookies can't be shared. So I had to use C# to insert Javascript to create cookies so I could do what I wanted. End result is an inelegant solution to what should be a simple problem (IMHO).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜