asp.netsharepointsharepoint-2010httpmodulespsite

How to detect events when user goes from one site collection to another in the same web application?


I have a several site collections in the same web application and I need to handle events when user goes from one site collection to another. I need it for specific actions, like setting "lcid" cookie for changing default language of site and claims values to user properties mapping.

Currently I'm using custom HTTP module, which handles all PostAuthorize web application requests and checks current user and site collection, holds last visited site for each user in collection and fires a custom event for subscribers, when detects transition between site collections.

But I think this approach slows down performance of web application. And from logs I see that there are to many PostAuthorize requests even when user simply clicks a link to page in other site collection. Also, in similar cases sometimes there is a series of requests to "next" site collection, then to "previous", and then again to "next". Also there are some issues with SharePoint Designer (can't edit page) become when this module is active.

Could you give me a advice with better approaches for this task? Thanks in advance.


Solution

  • 1 way is using a hidden control and cookie.
    Keep a hidden control in all the masterpage of all the targeted sitecollections. This control will check the current site collection url and save it in a cookie. Possibly in the same cookie where you are storing lcid.
    From next load onwards it will try and match the url in the cookie and the current site collection url. If different call the code you want to execute and update the url in the cookie.
    This will be much lighter on performance than an httpmodule.