Pages

HttpContext is Null


In ASP.Net application, HttpContext type will be instantiated for current thread and it loads all the context values related to the Request sent to the server. While we use the Asynchronous concept in the ASP.Net application, the HTTPContext will not have a reference or values in the asynchronous thread. Apart from the normal Page execution thread, new threads will be created for every Async task we are using, So while referring those Context objects Care should be taken. Otherwise the application will throw error.
HttpContext.Current object will be null, when we are using Asynchronous task [PageAsyncTask].
To avoid this or overcome this, capture the needed values from the base thread and share it with a static class to the other threads. This capturing of values should happen before the invoking of Async Calls.

No comments:

Post a Comment