nes*_*h_s 5 asp.net iis-7 static-html c#-4.0
我创建了一个简单的HttpModule,它在将响应发送到客户端之前从响应中删除空格.这适用于IIS7.0上的aspx页面,但如果我创建一个静态html页面并调用它,HttpModule不会启动(我知道的方式是因为源包含空格,否则本应删除).显然有些东西我做得不对,但不知道是什么.
我的网站位于.NET 4.0和.NET 4.0的应用程序池中ManagedPipelineMode = Integrated
.
我已将模块添加为ManagedModule,并引用GAC的强名称密钥程序集.
谢谢
编辑 - 这是web.config中的system.webserver部分
<system.webServer>
...
<modules runAllManagedModulesForAllRequests="true">
<add name="RemoveWhitespaceHttpModule"
type="HttpModules.Modules.RemoveWhitespaceHttpModule, HttpModules,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a83u4bi47o9fo0d"
preCondition="" />
</modules>
<defaultDocument>
<files>
<add value="TestForm.aspx" />
</files>
</defaultDocument>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
编辑 - 修正了它.对于任何感兴趣的人,这是我的模块检查响应然后决定是否继续删除空格的方式
if (contentType.Equals("text/html")
&& httpContext.Response.StatusCode == 200
&& httpContext.CurrentHandler != null)
{ ... }
Run Code Online (Sandbox Code Playgroud)
问题出在httpContext.CurrentHandler!= null之上的第三个条件.当为静态.html页面调用此模块时,currentHandler为null,因此代码永远不会进入操作html.我已经删除了这第三个条件,它现在有效.谢谢大家的回答
这应该可以解决问题,在 web.config 中:
<modules runAllManagedModulesForAllRequests="true"></modules>
Run Code Online (Sandbox Code Playgroud)
这是一个快速且简单的解决方案,但可能会导致问题/性能问题。