How to Fix the ASP.NET “Request Is Not Available in This Context” Error on IIS7

When migrating an older version of a .NET website to IIS on Windows 7, I encountered the following error:

 
 
“/” Application Server Error.
 
 
Request is not available in this context 
 
 
 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Web.HttpException: Request is not available in this context
 
 
This was quite strange, as there were no issues when debugging the application. It was clear that the problem was not related to the project itself, but rather to the environment — pointing to an issue with IIS 7.
 
After searching online for a while, the solution turned out to be simple: it was caused by a misconfiguration of the web application pool, an error seemingly unique to IIS 7.
 
How to Fix:
 
In IIS 7, navigate to the current application’s virtual directory, right-click, go to Manage Application, then Advanced Settings.
 
Change the application pool property from DefaultAppPool to Classic .NET AppPool (i.e., Classic mode).
 
Alternatively, you can go directly to Application Pools, double-click DefaultAppPool, change the “Managed Pipeline Mode” to Classic in the pop-up window, and click OK to save.
 
 
 
Note:
 
      In IIS 7, application pools have two modes: Integrated and Classic. The application pool mode affects how the server processes requests for managed code. If a managed application runs in an application pool using Integrated mode, the server uses the integrated request-processing pipeline of IIS and ASP.NET to handle requests. However, if a managed application runs in an application pool using Classic mode, the server continues to route managed code requests through Aspnet_isapi.dll, processing requests just as if the application were running in IIS 6.0.
 
      For more information on the Integrated mode of the managed pipeline in IIS 7 application pools, refer to “ASP.NET 3.0 Advanced Programming”.

Leave a Comment

Your email address will not be published.