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>

 

 

 

 

 

posted @ 2014-04-27 16:46  SmartBooks  阅读(170)  评论(0编辑  收藏  举报