ASP.NET防盗链
项目中提到了防盗链的需求,弄了一天总算弄好了,但是过了一段时间发现失效了。。后来发现原来是配置文件被覆盖了
之前参考了很多网上的资料,都说要在<system.web>标签下的<httpHandlers>标签添加
<add path="*.jpg,*.png,*.jpeg" verb="*" type="XunBaoDTCMS.Web.ashx.ImgProtectHandler,ImgProtectHandler" />
但是发布到IIS上去,发现访问图片不会进入到一般处理程序之中。
仔细回想上次的配置,我记得点进了这儿
添加完了之后发现web.config之后多出了以下配置:
<system.webServer>
.........
<handlers>
<add name="JPGProtectHandler" path="*.jpg" verb="GET" type="XunBaoDTCMS.Web.ashx.ImgProtectHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
<add name="PNGProtectHandler" path="*.png" verb="GET" type="XunBaoDTCMS.Web.ashx.ImgProtectHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
<add name="JPEGProtectHandler" path="*.jpeg" verb="GET" type="XunBaoDTCMS.Web.ashx.ImgProtectHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
<add name="GIFProtectHandler" path="*.gif" verb="GET" type="XunBaoDTCMS.Web.ashx.ImgProtectHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
</handlers>
</system.webServer>
原来是要在webServer中添加配置啊