开发者

How to handle *.txt requests in ASP.NET

开发者 https://www.devze.com 2023-02-03 20:26 出处:网络
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 w

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 MapRequ开发者_如何学PythonestHandler

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>


You probably need to remove the StaticFile handler:

<handlers>
    <remove name="StaticFile" />
</handlers>

UPDATE

Try the following (the order of HTTP handlers is important):

<handlers>
    <remove name="StaticFile" />

    <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" />
    <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
     resourceType="Either" requireAccess="Read" />  
</handlers>


You could use IIS Failed Request Tracing to see what actually gets requested and where it fails.


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" /> 
0

精彩评论

暂无评论...
验证码 换一张
取 消