简体   繁体   中英

how to set a handler in web.config with IIS7?

I have a handler, on runtime it create a watermark on images from a specific folder. The problem is that it worked, but now it doesn't.

All that I did was to changed the hosting.

My web.config looks like this:

<handler>
 <add verb="*" name="ImageWatermarkHandler" type="ImageWatermarkHandler" 
      path="Pics/*.jpg,Pics/*.png"  modules="IsapiModule"
      scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" 
      resourceType="Unspecified" preCondition="integratedMode" />
</handler>

Can you please help me?

Under IIS 7, you have to specify custom http handlers and modules under the configuration/system.webServer/handlers element of your web.config (unlike older IIS versions, where the element is configuration/system.web/httpHandlers ).

There's difference between integrated mode (you only need the handlers part) and classic mode(you need both handlers and httpHandlers). For details see the MSDN entry

Edit: At first I haven't noticed the precondition for integrated mode, could it be that the new hosting runs your app in classic mode?

your config file should look like this,

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="Pics/*.jpg,Pics/*.png" type="ImageWatermarkHandler"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <add verb="*" path="Pics/*.jpg,Pics/*.png" name="ImageWatermarkHandler" type="ImageWatermarkHandler"/>
    </handlers>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
</configuration>

for more information, http://msdn.microsoft.com/en-us/library/bb515343.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM