Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
Created March 19, 2013 13:14
Show Gist options
  • Select an option

  • Save ichiroku11/5196008 to your computer and use it in GitHub Desktop.

Select an option

Save ichiroku11/5196008 to your computer and use it in GitHub Desktop.
カスタムHTTPハンドラーとカスタムHTTPモジュールの作成・登録
using System;
using System.Web;
namespace WebApp.App_Code {
public class SampleHttpHandler : IHttpHandler {
public bool IsReusable {
get { return false; }
}
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = MimeMapping.GetMimeMapping(".txt");
context.Response.Write("SampleHttpHandler");
}
}
}
using System;
using System.Web;
namespace WebApp.App_Code {
public class SampleHttpModule : IHttpModule {
public void Dispose() {
}
public void Init(HttpApplication app) {
app.BeginRequest += (sender, e) => {
((HttpApplication)sender).Context.Response.AddHeader("X-SampleHttpModule", "BeginRequest");
};
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<!-- カスタムHTTPハンドラーの登録 -->
<handlers>
<add name="SampleHttpHandler" path="handler" verb="*" type="WebApp.App_Code.SampleHttpHandler" />
</handlers>
<!-- カスタムHTTPモジュールの登録 -->
<modules>
<add name="SampleHttpModule" type="WebApp.App_Code.SampleHttpModule"/>
</modules>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment