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 である可能性があります。

言及されたリンクからの引用:

このエラーは、Application_Start イベントで要求コンテキストを使用できなくする IIS7 統合パイプラインの設計変更が原因です。クラシック モード (以前のバージョンの 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 に答える