Contents tagged with Tips and Tricks

  • Tip/ Trick: Preventing Session Loss when using Cookieless sessions with TreeView and Menu controls

    By default .net runtime uses the cookies to remember the session Id between the requests ,
    but when using Cookie less sessions ,the runtime inserts the Session Id to the requested url  ,
    this way the runtime can remember the session id and prevent the session loss .

    The problem is , when using the Menu and TreeView Controls , these controls doesn't handle this issue ,
    so when those controls display there data from the Site maps, they didn't append the session id to the Navigation Urls of there Items ,
    and so when the User Navigate to a page using those controls , he will redirected to a Url that didn't contains the session Id,
    and so the runtime can't extract the session id , Hence the session will be  lost .

    The Solution:
    the solution  is to Manually Append the Session Id to NavigateUrl  of the Items for those Navigation controls,
    we can use HttpContext.Current.Response.ApplyAppPathModifier to modify the Item Urls as Follows:

    For the Menu Control , we can use MenuItemDataBound Event Handler to accomplish this: