Created
March 19, 2013 13:14
-
-
Save ichiroku11/5196008 to your computer and use it in GitHub Desktop.
カスタムHTTPハンドラーとカスタムHTTPモジュールの作成・登録
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| }; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考
チュートリアル : 同期 HTTP ハンドラーの作成
方法 : HTTP ハンドラーを登録する
チュートリアル : カスタム HTTP モジュールを作成および登録する