locked
Get ASP Classic Session Variables from ASP.net Class Module RRS feed

  • Question

  • User-1650322536 posted

    I'm developing a new ASP.Net Web Site from an existing Classic ASP site in VS2008. My client wanted the existing ASP pages be used along side the ASPX pages that are being developed.  The problem is how to pass session  variables between the asp and aspx pages.  I have one solution that involves opening an asp page and creating TextBoxes for each session variable and then posting it to an aspx page.  This works but requires the use of extra pages. 

    I was wondering if there is a way to do this in a C# Class Module (in ASP.net).  Remember that asp and aspx pages both exist in the Website.  If I logon on an asp.net page, the asp.net session variables are created.  Then if I logon on the asp logon page, the asp session variables are also created.  After I have logged on on both an asp page and an aspx page the session variables on  both sides are persistent.  That is I can go from asp to aspx and back  to asp and the asp session variables are retained in each.  

    I was hoping to do the transfer of session variables in an ASP.net class module.  I know I can get the asp.net session variables using

        HttpContent.Current.Session["<SessionVariableName>"]

    Since the ASP Session Variables  are persistent, I was hoping that there would be some way of accessing them.  Maybe something like

       Http.GetLocalResourceObject(<Asp Page Url>....)

    Any suggestions or is this a deadend?

     

     

     

    Wednesday, March 20, 2013 10:22 AM

Answers

  • User-760709272 posted

    It's a dead-end as while the files are in the same directory on the disc, that is where the interaction ends.  Your asp code is running in a different process than your .net code, you can't share session.  When you add "hello" to the session in .net you are adding an instance of the class System.String...how is your ASP code supposed to access that class and use it when it knows nothing about .net?  Likewise when it stores a COM-compliant string how is your .net code going to access it?  The solution is to pass session data where needed on the querystring or something (may need encryption) or some other hack.  Or don't do a partial site conversion, convert the whole thing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 20, 2013 11:31 AM

All replies

  • User-760709272 posted

    It's a dead-end as while the files are in the same directory on the disc, that is where the interaction ends.  Your asp code is running in a different process than your .net code, you can't share session.  When you add "hello" to the session in .net you are adding an instance of the class System.String...how is your ASP code supposed to access that class and use it when it knows nothing about .net?  Likewise when it stores a COM-compliant string how is your .net code going to access it?  The solution is to pass session data where needed on the querystring or something (may need encryption) or some other hack.  Or don't do a partial site conversion, convert the whole thing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 20, 2013 11:31 AM
  • User-1650322536 posted

    I have been playing around with this and it appears that session variables set on aspx pages are available on asp pages.  I was under the understanding that that was not the case.  Here is what I did.  I declared a session variable that is used on aspx pages (LoginUserID) and a session variable that is used on asp pages (UserID) in the Global.asax  page.  Then in the userlogin.aspx page I set the values for both the LoginUserID and UserID when the user logs in. 

    At the current time my NavBar points to either asp or aspx pages depending on which pages have been converted already.  Prior to setting the UserID, the system would request an asp login when I landed on an asp page the first time.  With the change to setting UserID on the aspx UserLogin Page, it  seems to know the value and doesn't ask for a login. 

    I thought this was not possible.  Is the current operation correct?

    What I haven't tested is setting a session variable on an asp page and seeing if it is available on an aspx page.  I suspect this is where they are not compatible.  However I only used the LoginUserID session variable on the aspx side and this is generated on the userLogin.aspx page  so this capability is not needed. 

     

     

    Wednesday, March 20, 2013 11:49 AM
  • User-1650322536 posted

    An error is the testing procedure resulted in invalid results.  Session Variables cannot be passed from aspx pages to asp pages as described above.

    Wednesday, March 20, 2013 3:55 PM