2009-07-14 4 views
9

私はSoftsys Hostingについて良いことを聞いたので、私は自分のASP.NET MVCソリューションをそれらに移すことに決めました。しかし、それはそれらに実行されません。 BeginRequestイベントハンドラに問題を突き止めることができました。もし私がそれらを持っていたら、私はエラーを起こすだろう。ここに私のコードです。私のホスト(softsyshosting.com)がBeginRequestおよびEndRequestイベントハンドラをサポートしないのはなぜですか?

protected void Application_Start() 
{ 
    RegisterRoutes(RouteTable.Routes); 
    this.BeginRequest += new EventHandler(MvcApplication_BeginRequest); 
    this.EndRequest += new EventHandler(MvcApplication_EndRequest); 
} 

void MvcApplication_EndRequest(object sender, EventArgs e) 
{ 
} 

void MvcApplication_BeginRequest(object sender, EventArgs e) 
{ 
} 

デフォルトのASP.NET MVCアプリケーションを作成し、上記のコードを追加するだけで問題を再現できます。奇妙なことは、このコードは私の古いホストで正常に動作し、新しい(共有)ホストでのみクラッシュすることです。私は私のコードでこれらのイベントハンドラを持っている場合、私はこのエラーを取得する:

Server Error in '/' Application.   Object reference not set to an instance of an object. 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.NullReferenceException: Object reference not set to an instance of an object.

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:

[NullReferenceException: Object reference not set to an instance of an object.] System.Web.PipelineModuleStepContainer.GetStepArray(RequestNotification notification, Boolean isPostEvent) +27 System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent) +11 System.Web.PipelineStepManager.ResumeSteps(Exception error) +205 System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +91 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +514

私はSoftsysと、このトラブルシューティングを試してみましたが、彼らは非常に有用ではなかった、基本的に彼らはちょうど私が「ASP.NETパイプラインになっていたことを確認しました(MVC)」機能を使用することができます。

誰かができます:私は

  • 何か間違ったことをコード化した場合

    1. が教えてはくれ
    2. このエラーがあるホスト上でoccuringや他のされていない理由を私に説明回避策を表示します。
  • +0

    ことではなく、あなたのホスティング事業者の支援のための問題ではないでしょうか? –

    +0

    万が一NHibernateを使用していますか? –

    +0

    Oliver、はい私はSoftsys Hostingからのサポートを得ようとしましたが、あまり役に立ちませんでした。彼らはこれを解決するために私に$ 95/HRを請求したかった。私は彼らのことについて他には満足していたし、もし私が間違っているとしたら、それらをあきらめたくない。 Dreas、いいえNHibernateを使用していません。 – Whozumommy

    答えて

    7

    IIS 6またはIIS 7クラシックモードからIIS 7統合モードに移行したように見えます。 IIS 7統合モードでは、要求処理はアプリケーションの開始から切り離されていました。 This articleは、理由と場所を説明しています。

    これを修正するには、コードをApplication_BeginRequestに移動する必要があります。

    16

    各HttpApplicationインスタンスにハンドラを登録する必要があります。プールされたHttpApplicationのインスタンスがいくつか存在することがあります。 Application_Startは一度だけ呼び出されます(古典的なモードのIIS 6とIIS 7では、最初のリクエストで、IIS 7の統合モードでは、Webアプリケーションの開始時に、リクエストの直前に呼び出されます)。したがって、すべての作業を行うには、HttpApplicationのオーバーライドされたInitメソッドまたはそのコンストラクタでイベントハンドラを追加する必要があります。コンストラクタでそれらを追加すると、登録されたモジュールのハンドラの前であっても、これらのハンドラが最初に呼び出されます。
    は、だからあなたのコードは次のようになります。

    public class MySmartApp: HttpApplication{ 
        public override void Init(){ 
         this.BeginRequest += new EventHandler(MvcApplication_BeginRequest); 
         this.EndRequest += new EventHandler(MvcApplication_EndRequest); 
        } 
        protected void Application_Start(){ 
         RegisterRoutes(RouteTable.Routes); 
        } 
    } 
    

    またはこのような:

    public class MySmartApp: HttpApplication{ 
        public MySmartApp(){ 
         this.BeginRequest += new EventHandler(MvcApplication_BeginRequest); 
         this.EndRequest += new EventHandler(MvcApplication_EndRequest); 
        } 
        protected void Application_Start(){ 
         RegisterRoutes(RouteTable.Routes); 
        } 
    } 
    
    +0

    これは素晴らしい情報ですが、私はこの問題を解決できないと考えています。私はApplication_OnStartにハンドラを登録せずにこの問題を再現することができます(もちろん、reproは私にとっては散発的です)。このエラーが実際に何を意味しているのか(それが何であるかを調べることは役に立ちます) –

    +0

    上記の情報に関するいくつかのリンクを提供できますか?おそらくMSDNの記事ですか? –

    +0

    偉大な答え。私の問題を解決しました。これは.NET 4.5、MVC 4、IIS 8上にありました。 –

    関連する問題