Sample ASP.NET IHttpHandler

LoggerHandler.cs

using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Linq;

using System.Web;



namespace SampleHttpModel.Handlers

{

    public sealed class LoggerHandler : IHttpHandler

    {

        public bool IsReusable

        {

            get { return false; }

        }



        public void ProcessRequest(HttpContext context)

        {

            Debug.WriteLine(context.Request.RawUrl);

            

            context.Response.Write("sucess-HttpHandler");

            context.Response.End();

        }

    }

}

Web.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <system.web>

    <compilation debug="true" targetFramework="4.5" />

    <httpRuntime targetFramework="4.5" />

  </system.web>

  <system.webServer>

    <handlers>

      <add name="Logger" path="*" verb="*" type="SampleHttpModel.Handlers.LoggerHandler" resourceType="Unspecified" preCondition="integratedMode" />

    </handlers>

    <modules>

      <add name="LoggerModels" type="SampleHttpModel.HandlerModels.LoggerModels" preCondition="managedHandler" />

    </modules>

  </system.webServer>

</configuration>

 

 

 

 

 

你可能感兴趣的:(asp.net)