Using Session state to store objects

Hi

I want to save an object, and make it available over several pages. So far it seems the best way for me to do this is to use sessions. However I can't find a way to store an object for the duration of a session. Below is some of the code

Fragment of Method 1

SearchResultCollection ownerResults = Code to return SearchResultCollection

Session["ownerResults"] = ownerResults;

Fragment of Method 2

SearchResultCollection ownerResults = Session["ownerResults"];

However, I get the following error.

Error 1 Cannot implicitly convert type 'object' to 'System.DirectoryServices.SearchResultCollection'. An explicit conversion exists (are you missing a cast )

My question is, how can I store an object, to be used by the same page, or different page in the same session

Thanks

Ben



Answer this question

Using Session state to store objects

  • Fwank79

    Hi Ben,

    You should try posting to the ASP.NET web forums at:

    http://forums.asp.net

    This forum is more specific to ASP.NET Web Services.

    Daniel Roth



  • Jebat

    Thanks for the reply. However casting would not work and gave an error.

    However, I got a response from the asp.net site which did work. See thread

    http://forums.asp.net/1214638/ShowPost.aspx

    Thanks for the help

    Ben


  • almazv

    You need to cast it back.

    SearchResultCollection ownerResults = (SearchResultCollection) Session["ownerResults"];


  • Using Session state to store objects