ASP.NET: Multiple Session objects in a single application

前端 未结 4 1459
死守一世寂寞
死守一世寂寞 2020-12-19 23:56

I have one ASP.NET web application running at the web server root which provides multiple (similar) web sites by using URL redirection. To give a real world example:

4条回答
  •  北海茫月
    2020-12-20 01:00

    Depending on how you're adding and retrieving items to and from the Session (and possibly dependent on whether you're deriving your pages from a common base page), you might be able to do a custom object that wraps the session without breaking all of your code (as mentioned in your first option where you have a session wrapper implemented as a hash map keyed by site). If you create a custom object and expose it as "Session" at the base page level, it will take precedence over the Session object you inherit from the Page class. Then, your custom object can override the indexers and make the determination where in the hashmap to store this object based on the request url of the current http context.

    If you're not deriving from a common base page, this kinda goes out the window because then you'd have to either implement a base page for all pages to derive from or add code to each page to get a reference to your object. Just and idea...

提交回复
热议问题