在web.config中注册httpModules

Pra*_*gus 22 c# asp.net

我试图在web.config文件中注册自定义HttpHandler.MSDN的示例显示了一个被注释掉的条目...嗯,它不能很好地工作.当我取消注释时,我收到Could not load file or assembly 'HttpModule.cs' or one of its dependencies. The system cannot find the file specified.错误.文件名是HttpModule.cs,类名是MyHttpModule.还没有明确的命名空间.

<httpModules>
     <add name="MyHttpModule" type="MyHttpModule, HttpModule" />
<httpModules>
Run Code Online (Sandbox Code Playgroud)

我相信我忽视了显而易见的事实.我需要在某处指定文件路径吗?提前致谢.

Pra*_*gus 19

我仍在学习很多术语,需要为我详细说明.万一你们需要相同的......

作为一个例子,如果:

  • 基类名称和项目名称是 TestSite
  • 我的类所在的命名空间是 BusinessLogic
  • 班级名称是 PageAuthorization

在Web.config文件中...

<configuration> 
 <system.web> 
  <httpModules> 
   <add type= "BusinessLogic.PageAuthorization, TestSite" name="PageAuthorization" /> 
  </httpModules> 
 </system.web> 
</configuration>
Run Code Online (Sandbox Code Playgroud)

在我的情况下,我必须标记我的课程IHttpModule.该类的定义如下:

public class PageAuthorization : IHttpModule
Run Code Online (Sandbox Code Playgroud)

  • 如果我的模块文件在网站的App_Code文件夹中怎么办? (3认同)

小智 15

如果从.Net 4.0 GAC和IIS 6/7经典模式加载自定义模块,则必须使用以下代码

 <system.web>
  <httpModules>
  <add name="ClientHttpModule" type="ClientServHttpModule.ClientHttpModule,ClientServHttpModule,Version=1.0.0.0, Culture=neutral, PublicKeyToken=3af8d8e2f9e8b6c3" />
      </httpModules>
 </system.web>
Run Code Online (Sandbox Code Playgroud)

ClientServHttpModule是自定义模块的命名空间.您可以从sn.exe应用程序获取公钥令牌.

如果您在集成模式下运行.请使用以下代码

<system.webServer>
        <modules>
            <add name="ClientHttpModule" type="ClientServHttpModule.ClientHttpModule,ClientServHttpModule,Version=1.0.0.0, Culture=neutral, PublicKeyToken=3af8d8e2f9e8b6c3" />
        </modules>
    </system.webServer>
Run Code Online (Sandbox Code Playgroud)


Mit*_*ers 14

type值是格式{Class}, {assembly}.

所以在你的情况下,它应该是 MyHttpModule, MyDllName

MyDllName编译的DLL的名称在哪里.


Sud*_*hra 5

登陆此处寻找以集成模式运行的 IIS 7 及更高版本的配置的注意事项:

<configuration> 
 <system.webServer> 
  <modules> 
   <add type= "BusinessLogic.PageAuthorization, TestSite" name="PageAuthorization" /> 
  </modules> 
 </system.webServer> 
</configuration>
Run Code Online (Sandbox Code Playgroud)