How to apply a custom handlers to only specific fo

2019-07-21 17:37发布

问题:

I use Asp.Net 4 C# and IIS 7.5.

In web.config I was able to apply my handler with success (code below) as you can see path="*.jpg" let the handler operate in any folder of my website.

I need instead apply this handler to all .jpg request but ONLY in a specific folder, in my case /Cdn/Cms/Images/

So I update to path="/Cdn/Cms/Images/*.jpg" but the handler does not apply.

I tried many times with different paths but now way.

How can I apply a handler to only a specific folder?

Thanks for your time on this.

This question is related to this one

   <system.webServer>
...
        <validation validateIntegratedModeConfiguration="false" />

        <handlers>
            <add name="Cms-ImageRouteHandler" path="*.jpg" verb="*" type="WebProject.Cms.BusinessLogics.SEO.Routing.ImageRouteHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
        </handlers>
...

回答1:

Try creating the /Cdn/Cms/images folder structure in your website folder and then create a web.config in that folder with just the following:

<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
            <add name="Cms-ImageRouteHandler" path="*.jpg" verb="*" type="WebProject.Cms.BusinessLogics.SEO.Routing.ImageRouteHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
        </handlers>
    </system.webServer>
</configuration>

You can then remove it from your main site's web.config. See if that works.