HttpHandler简单示例

using System.Web;

namespace MyWebApp
{

    public class MyHttpHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("这一部分是由HttpHandler添加!");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

webconfig配置:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ApplicationInsightsWebTracking"/>

      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>



    </modules>
    <handlers>
      <remove name="MyHttpHandler"/>
      <add name="MyHttpHandler" verb="*" path="*.jsp" type="MyWebApp.MyHttpHandler"/>
    </handlers>
  </system.webServer>

注:<system.webServer> <validation validateIntegratedModeConfiguration="false"/> 这句很重要,不然iis可能不支持

原文地址:https://www.cnblogs.com/gaocong/p/6734909.html