13

asp.net アプリケーション (v 3.5、Visual Studio 2008) にいくつかの http モジュールを統合したいのですが、web を実行すると起動する asp.net 開発サーバーでデバッグ中にそのようなモジュールをデバッグまたは使用する方法がわかりません。アプリ。

ソリューションにモジュール ソースを含める必要がありますか、それとも DLL を BIN にドロップするだけでよいですか? 私は 1.1 の世界出身で、まだ asp.net 開発サーバーに慣れていません。

4

5 に答える 5

11

Two common reasons for breakpoints not being hit in an HttpModule are:

The breakpoint is in code that is called during the module's construction.

This one always get's me. If you want to debug the module's construction you should manually attach the debugger. To do this on Windows 7 (it'll be similar on Vista):

  1. Debug | Attach to Process...
  2. Check Show processes in all sessions.
  3. Select the your worker process instance (w3wp.exe)
  4. Click Attach.

Refresh your browser and you should now hit your breakpoint.

The module is not actually being loaded because of a configuration issue.

If you can tell that the module code is definitely being executed then this is not the problem. But sometimes, while a module is loading fine on other machines it might not be loading on your dev box because you have a different version of IIS and you don't have the necessary config.

If this is the the case then make sure the module is wired up correctly for all required versions of IIS.

For IIS 5.1 and IIS 6...

<system.web>
  <httpModules>
    <add name="CustomHttpModule" type="MyCustomHttpModule"/>
  </httpModules>
</system.web>

...and for IIS 7+

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="CustomHttpModule" type="MyCustomHttpModule"/>
  </modules>
</system.webServer>
于 2010-04-06T13:29:23.017 に答える
5

これはそのままでは機能しないように見えることに注意してください。新しいモジュールのクラス名を含めるだけでなく、その名前空間と (念のため) アセンブリを明示的に定義してください。これを怠ると、コーディングしたばかりの新しい HTTP モジュールを読み込めないという IIS のエラーが発生する可能性が高くなります。

以下に例を示します。

それ以外の:

<add name="CustomHttpModule" type="MyCustomHttpModule"/>

使用する:

<add name="CustomHttpModule" type="MyCustomRootNamespace.MyCustomHttpModule, MyCustomAssembly"/>

そうしないと、プロジェクトの読み込みに失敗する可能性があります。

受け取る可能性のある特定のエラーは、モジュールをどの程度明示的に定義したかによって異なります。名前空間を省略すると、次のように表示されます。

Could not load type 'MyCustomHttpModule'.

名前空間を省略してアセンブリを含めると、代わりに次のように表示されます。

Could not load type 'MyCustomHttpModule' from assembly 'MyCustomAssembly'. 

代わりに別のエラー メッセージが表示される場合は、ここで説明したものとは別の問題が発生しています。

于 2011-01-10T03:06:52.153 に答える
2

あなたは行を書くことができます

System.Diagnostics.Debugger.Break(); // Break を明示的に呼び出してデバッグする

HttpModule 構築中にブレークポイントを明示的に呼び出す。

プロセス (例: w3wp.exe) をアタッチするように求められ、デバッグ ポイントがヒットします。

ありがとう

于 2015-03-12T11:15:03.437 に答える