Search code examples
asp.nethttphandlerhttpmodule

How to handle *.txt requests in ASP.NET


I've running asp.net application under IIS7 in classic mode. I've already created script mapping to '*' with ISAPI module, but when i perform txt request (even if it not exists) i get 404 error with:

Notification MapRequestHandler

Handler StaticFile

and no event is fired in Global.asax or modules. Do i missed something?

<system.web>
...
<httpHandlers>
    <add verb="*" path="*" validate="false" type="TestCustomExtensions.TextFileHandler, TestCustomExtensions" />
</httpHandlers>
<httpModules>
    <add name="text" type="TestCustomExtensions.TextModule"/>
</httpModules>
</system.web>

<system.webServer>
...
<modules>
   <add name="textModule" type="TestCustomExtensions.TextModule"/>
</modules>
<handlers>
   <add name="TextFiles" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
</handlers>
,</system.webServer>

Solution

  • Resolved!

    The problem was in my OS. I have 64x windows installed, but in config file i set 32x path to ISAPI dll. So, to resolve this, i've added two lines, to handle both 32x and 64x OS.

    <add name="TestFiles64" path="*.txt" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
    <add name="TextFiles32" path="*.txt" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />