ASP.Net Web Service| Session | Access to Session pool RRS feed

  • Question

  • Hi

    Hi we are writing an ASP.Net web service.


    which of the structure String Execute(String inputXML)


    We need to develope an application in which the Session ID will be passed to us in non standard way ie we dont get Session ID in cookie or in the URL.


    The Session ID will be passed to us the part of the inputXML which also contains the parameters for operation and other details for execution.


    We need to tie the input session in the call to the session.


    Some of the mechanisms we have thought of


    1. We can make a proxy web service in which the URL is rewritten such that Session ID is made a part of URL

    2. We may rewrite the URL itself in a new HttpModule and rewrite the URL so that session is automatically attached.


    How I would like to Solve this


    Though I am not aware how session is managed in ASP.Net internally in a lot of detail but I would beleive there should be a singleton or static class in the web servicr which manages all the sessions.


    For now if we call it SessionPool


    what I want to do is Session = SessionPool[SessionID <<Passed from input XML ]


    kind of job.



    We know that we will be using SQL Server for State management, I will be ok if there are API's which we can use to get the session out of SQL Server and tie it to our request.




    I dont know how to get a handel in ASP.Net to the pool of all session objects. Any help in pointing to this direction will be great.







    Friday, October 10, 2008 9:15 AM

All replies

  • Hi,


    You could set ASP.NET application to use cookieless session handling



    Then the session id will be written in the URL by default and interpreted by the ASP.NET engine to load the correct session (wether it is in a database or in state service or whatever the web.config is saying).


    http://yourserver/folder/(session ID here)/default.aspx

    So if you can rewrite the url as above with the session in it, your home free. I guess with your #1 solution you mentioned above.


    Accessing the session store and setting a session based on an id is hard I believe, not a common approach.

    Thursday, October 16, 2008 7:44 AM
  • AFAIK the only way to achieve that is to roll your own Session State provider, have a look here:

    Another solution would be to build your own state manager, it's fairly simple to do, with a simple dictionary, weak references and a clean up thread that kills objects.

    And in your call get it from your own provider, something like:

    var state = stateManager.GetStateFor(myId);

    Thursday, October 16, 2008 3:54 PM