0

我开发了一个 asp.net mvc3 应用程序,它在 localhost 上运行良好,但是当我使用所有 .dll 在线托管时,它给出了错误

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

我该如何解决?我已经尝试了很多

谢谢

4

3 回答 3

2

不确定这是否对某人有帮助.. 但我将应用程序池设置为 Classic .NET AppPool 并且错误消失了。

马丁

于 2012-07-16T10:07:42.010 回答
1

适用吗?服务器显然是 IIS7,而您的本地主机可能是 IIS6。

从提到的链接引用:

此错误是由于 IIS7 集成管道中的设计更改导致 Application_Start 事件中的请求上下文不可用。当使用经典模式(在以前版本的 IIS 上运行时的唯一模式)时,请求上下文过去是可用的,即使 Application_Start 事件一直旨在作为应用程序生命周期中的全局且与请求无关的事件。尽管如此,由于 ASP.NET 应用程序总是由应用程序的第一个请求启动,因此过去可以通过静态 HttpContext.Current 字段访问请求上下文。

于 2012-07-10T04:22:55.407 回答
0

请用

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

代替

Response.Redirect("PageName");

在你的代码中。

于 2015-12-23T06:49:19.697 回答