0

I developed a asp.net mvc3 application, It's working fine at localhost, but when i hosted online with all .dlls, it gives error

Server Error in '/' Application.

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

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpContext.get_Request() +8828580
   atulitbaldhama.MvcApplication.Application_Start() in D:\2012\atulitbaldhama\atulitbaldhama\atulitbaldhama\Global.asax.cs:66

[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9093225
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9013676
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

How can i solve it ? I have tried a lot

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
shailendra
  • 205
  • 1
  • 8
  • 21

3 Answers3

2

Not sure if this helps someone.. But i set the Application Pool to Classic .NET AppPool and the error disappeared.

Martin

brenmartin
  • 31
  • 1
  • 2
1

Does this apply? The server is obviously IIS7, and your localhost might be IIS6.

Quoting from the link mentioned:

This error is due to a design change in the IIS7 Integrated pipeline that makes the request context unavailable in Application_Start event. When using the Classic mode (the only mode when running on previous versions of IIS), the request context used to be available, even though the Application_Start event has always been intended as a global and request-agnostic event in the application lifetime. Despite this, because ASP.NET applications were always started by the first request to the app, it used to be possible to get to the request context through the static HttpContext.Current field.

Community
  • 1
  • 1
Michael
  • 8,891
  • 3
  • 29
  • 42
0

Please use

 HttpContext.Current.Response.Redirect("PageName");

instead of

Response.Redirect("PageName");

in your code.

smottt
  • 3,272
  • 11
  • 37
  • 44
Rita Chavda
  • 191
  • 2
  • 16