如何将自定义处理程序仅应用于特定文件夹 [英] How to apply a custom handlers to only specific folder

查看:95
本文介绍了如何将自定义处理程序仅应用于特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Asp.Net 4 C#和IIS 7.5.

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

在web.config中,我能够成功应用我的处理程序(下面的代码),如您所见,path="*.jpg"让处理程序在我网站的任何文件夹中运行.

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.

相反,在我的情况下,我需要应用此处理程序to all .jpg request but ONLY in a specific folder

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

所以我更新到path="/Cdn/Cms/Images/*.jpg",但是该处理程序不适用.

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?

感谢您的宝贵时间.

此问题与

推荐答案

尝试在您的网站文件夹中创建/Cdn/Cms/images文件夹结构,然后仅使用以下内容在该文件夹中创建一个web.config:

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>

然后可以将其从主站点的web.config中删除.看看是否可行.

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

这篇关于如何将自定义处理程序仅应用于特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆