Ajax PageMethods with Cookie-less Sessions
Earlier this week I had to implement an auto-complete textbox (ala Google Suggest) in a web application. As much as I wanted to use the newly-supported-by-MS jQuery framework, the application was already using the ASP.NET Ajax library, so I used the AutoCompleteExtender control from the AjaxToolkit.
However, the implementation took longer than expected, so I thought I’d better blog the problem so I don’t spend too long debugging it the next time it happens!
Right, back to basics, so I used the fantastic FireBug add-on to check what was being requested from the server, and there was the problem. The request to the PageMethod was returning 500 - Server Error. However, IIS was serving this error before any of my code was being executed. I decided to create a simple project with the AutoCompleteExtender so that I could test in isolation.
ARGH! It works in the test project! It’s exactly the same!! Then, it twigged, the ‘real’ application uses cookieless sessions. Set that in the web.config of the test application. Boom! IIS returned Server Error. Excellent. PageMethods don’t work with SessionID’s in the Url. Thanks. For. That.
By setting the Extender control to use a WebService instead of a PageMethod everything worked as expected. Now to get the wasted 2 hours of my life back…