0

重複の可能性:
BasicAuthenticationModuleが見つからないのはなぜですか?

基本認証の独自の実装を作成しようとしています。

私はBasicAuthenticationModule.cs自分に保存し、solution\Modulesその名前空間は次のとおりです。

namespace Web_API.Modules
{
    public class BasicAuthenticationModule : IHttpModule

私はそれを私のweb.configにそのように追加しました:

  <system.webServer>
    <modules>
      <add name="MyBasicAuthenticationModule" type="Web_API.Modules.BasicAuthenticationModule, BasicAuthenticationModule" />

これを実行すると、次のエラーが発生します。

Server Error in '/' Application.

Could not load file or assembly 'BasicAuthenticationModule' or one of its dependencies. The system cannot find the file specified.

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.IO.FileNotFoundException: Could not load file or assembly 'BasicAuthenticationModule' or one of its dependencies. The system cannot find the file specified.

私はここで何が間違っているのですか?

4

1 に答える 1

3

モジュールに間違ったアセンブリ名を指定したようです。あなたが書くとき:

type="Web_API.Modules.BasicAuthenticationModule, BasicAuthenticationModule"

BasicAuthenticationModuleこれは、と呼ばれるアセンブリ内のWeb_API.Modules名前空間内で呼び出されるクラスをロードすることを意味しますBasicAuthenticationModule。このクラスを定義したプロジェクトは呼ばれていますBasicAuthenticationModuleか?私はそうは思わない。そのため、ASP.NETはモジュールを読み込めません。このモジュールが定義されている正しいアセンブリ名を指定する必要があります。

たとえば、ASP.NET MVCアプリケーションが呼び出された場合MvcAPplication1、定義は次のようになります。

type="Web_API.Modules.BasicAuthenticationModule, MvcApplication1"

type属性の形式は次のようになります。

type="Namespace.ClassName, AssemblyName"
于 2013-02-02T22:54:26.470 に答える