IHttpHandlerFactory.GetHandler メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > IHttpHandlerFactory.GetHandler メソッドの意味・解説 

IHttpHandlerFactory.GetHandler メソッド

IHttpHandler インターフェイス実装するクラスインスタンス返します

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Function GetHandler ( _
    context As HttpContext, _
    requestType As String, _
    url As String, _
    pathTranslated As String _
) As IHttpHandler
Dim instance As IHttpHandlerFactory
Dim context As HttpContext
Dim requestType As String
Dim url As String
Dim pathTranslated As String
Dim returnValue As IHttpHandler

returnValue = instance.GetHandler(context, requestType, url, pathTranslated)
IHttpHandler GetHandler (
    HttpContext context,
    string requestType,
    string url,
    string pathTranslated
)
IHttpHandler^ GetHandler (
    HttpContext^ context, 
    String^ requestType, 
    String^ url, 
    String^ pathTranslated
)
IHttpHandler GetHandler (
    HttpContext context, 
    String requestType, 
    String url, 
    String pathTranslated
)
function GetHandler (
    context : HttpContext, 
    requestType : String, 
    url : String, 
    pathTranslated : String
) : IHttpHandler

パラメータ

context

HTTP 要求処理するために使用する組み込みサーバー オブジェクト (たとえば、RequestResponseSession、および Server) への参照提供する HttpContext クラスインスタンス

requestType

クライアント使用する HTTP データ転送メソッド (GET または POST)。

url

要求されリソースの RawUrl。

pathTranslated

要求されリソースの PhysicalApplicationPath。

戻り値
要求処理する新しIHttpHandler オブジェクト

使用例使用例

クライアント要求に応じてカスタム ハンドラ オブジェクト作成する方法次のコード例示します。この例は、2 つ部分構成されます。

この例の最初部分では、abc.aspx または xyz.aspx. のいずれかの名前のページ求めクライアント要求への応答として、カスタム ハンドラ オブジェクト作成する方法示しますhwf という名前のハンドラ ファクトリ クラスが、要求されページに応じて適切なハンドラ オブジェクト作成します

' Name this Visual Basic file HandlerFactoryTest.vb and compile it with
 
' the command line: vbc /t:Library /r:System.Web.dll HandlerFactoryTest.vb.
' Copy HandlerFactoryTest.dll to your \bin directory.
Imports System
Imports System.Web

Namespace test    
    
    ' Factory class that creates a handler object based on a request
 
    ' for either abc.aspx or xyz.aspx as specified in the Web.config
 file.
    Public Class MyFactory
        Implements IHttpHandlerFactory
        
        <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
        Public Overridable Function
 GetHandler(context As HttpContext, _
        requestType As String, url As
 String, pathTranslated As String)
 _
        As IHttpHandler _
        Implements IHttpHandlerFactory.GetHandler
        
            Dim fname As String
 = url.Substring(url.LastIndexOf("/"c) + 1)
            Dim cname As String
 = fname.Substring(0, fname.IndexOf("."c))
            Dim className As String
 = "test." & cname
            
            Dim h As Object
 = Nothing
            
            Try ' to create the handler object.
                ' Create by calling class abc or class xyz.
                h = Activator.CreateInstance(Type.GetType(className))
            Catch e As Exception
                Throw New HttpException("Factory
 couldn't create instance " & _
                    "of type " & className, e)
            End Try
            Return CType(h, IHttpHandler)
        End Function
        
        
        ' This is a must override method.
        Public Overridable Sub
 ReleaseHandler(handler As IHttpHandler) _
        Implements IHttpHandlerFactory.ReleaseHandler
        
        End Sub
        
    End Class
    
    
    ' Class definition for abc.aspx handler.
    Public Class abc
        Implements IHttpHandler
        
        Public Overridable Sub
 ProcessRequest(context As HttpContext) _
        Implements IHttpHandler.ProcessRequest
        
            context.Response.Write("<html><body>")
            context.Response.Write("<p>ABC Handler</p>"
 & _
                Microsoft.VisualBasic.ControlChars.CrLf)
            context.Response.Write("</body></html>")
        End Sub        
        
        Public Overridable ReadOnly
 Property IsReusable() As Boolean
 _
        Implements IHttpHandler.IsReusable
        
            Get
                Return True
            End Get
        End Property
    End Class
     
    ' Class definition for xyz.aspx handler.
    Public Class xyz
        Implements IHttpHandler
        
        Public Overridable Sub
 ProcessRequest(context As HttpContext) _
        Implements IHttpHandler.ProcessRequest
        
            context.Response.Write("<html><body>")
            context.Response.Write("<p>XYZ Handler</p>"
 & _
                Microsoft.VisualBasic.ControlChars.CrLf)
            context.Response.Write("</body></html>")
        End Sub
        
        
        Public Overridable ReadOnly
 Property IsReusable() As Boolean
 _
        Implements IHttpHandler.IsReusable
        
            Get
                Return True
            End Get
        End Property
    End Class
End Namespace

'______________________________________________________________
'
'To use the handler factory, use the following lines in a
'Web.config file. (be sure to remove the comment markers)
'
'<configuration>
'   <system.web>
'      <httpHandlers>
'         <add verb="*" path="abc.aspx" type="test.MyFactory
,HandlerFactoryTest"
 />
'         <add verb="*" path="xyz.aspx" type="test.MyFactory
,HandlerFactoryTest"
 />
'      </httpHandlers>
'   </system.web>
'</configuration>


// Name this C# file HandlerFactoryTest.cs and compile it with the
// command line: csc /t:Library /r:System.Web.dll HandlerFactoryTest.cs.
// Copy HandlerFactoryTest.dll to your \bin directory.

namespace test
{
   using System;
   using System.Web;

   // Factory class that creates a handler object based on a request
 
   // for either abc.aspx or xyz.aspx as specified in the Web.config
 file.
   public class MyFactory : IHttpHandlerFactory
   {
      [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name = "FullTrust")]
      public virtual IHttpHandler GetHandler(HttpContext context,
 
                                             String requestType, 
                                             String url, 
                                             String pathTranslated)
      {
         String fname = url.Substring(url.LastIndexOf('/')+1);
         String cname = fname.Substring(0, fname.IndexOf('.'));
         String className = "test." + cname;

         Object h = null;

         // Try to create the handler object.
         try 
         {
            // Create the handler by calling class abc or class xyz.
            h = Activator.CreateInstance(Type.GetType(className));
         }
         catch(Exception e)
         {
            throw new HttpException("Factory couldn't create
 instance " +
                                    "of type " + className, e);
         }
         return (IHttpHandler)h;
      }

      // This is a must override method.
      public virtual void ReleaseHandler(IHttpHandler
 handler)
      {
      }
   }
   
   // Class definition for abc.aspx handler.
   public class abc : IHttpHandler
   {
      public virtual void ProcessRequest(HttpContext
 context)
      {
         context.Response.Write("<html><body>");
         context.Response.Write("<p>ABC Handler</p>\n");
         context.Response.Write("</body></html>");
      }
    
      public virtual bool IsReusable
      {
         get { return true;
 }
      }
   }

   // Class definition for xyz.aspx handler.
   public class xyz : IHttpHandler
   {
      public virtual void ProcessRequest(HttpContext
 context)
      {
         context.Response.Write("<html><body>");
         context.Response.Write("<p>XYZ Handler</p>\n");
         context.Response.Write("</body></html>");
      }
    
      public virtual bool IsReusable
      {
         get { return true;
 }
      }
   }
}

/*
______________________________________________________________

To use the handler factory, use the following lines in a 
Web.config file.

<configuration>
   <system.web>
      <httpHandlers>
         <add verb="*" path="abc.aspx" type="test.MyFactory
,HandlerFactoryTest"
 />
         <add verb="*" path="xyz.aspx" type="test.MyFactory
,HandlerFactoryTest"
 />
      </httpHandlers>     
   </system.web>
</configuration>
*/
   
package test; 
// Name this J# file HandlerFactoryTest.jsl and compile it with the
// command line: vjc /t:Library /r:System.Web.dll HandlerFactoryTest.jsl.
// Copy HandlerFactoryTest.dll to your \bin directory.

import System.*;
import System.Web.*;

// Factory class that creates a handler object based on a request 
// for either abc.aspx or xyz.aspx as specified in the Web.config file.
public class MyFactory implements IHttpHandlerFactory
{
    public IHttpHandler GetHandler(HttpContext context, String
 requestType,
        String url, String pathTranslated) throws HttpException
    {
        String fname = url.Substring((url.LastIndexOf('/') + 1));
        String cname = fname.Substring(0, fname.IndexOf('.'));
        String className = "test." + cname;
        Object h = null;

        // Try to create the handler object.
        try {
            // Create the handler by calling class abc or class xyz.
            h = Activator.CreateInstance(Type.GetType(className));
        }
        catch (System.Exception e) {
            throw new HttpException("Factory couldn't create
 instance "
                + "of type " + className, e);
        }
        return ((IHttpHandler)h);
    } //GetHandler

    // This is a must override method.
    public void ReleaseHandler(IHttpHandler
 handler)
    {
    } //ReleaseHandler
} //MyFactory

// Class definition for abc.aspx handler.
public class abc implements IHttpHandler
{
    public void ProcessRequest(HttpContext
 context)
    {
        context.get_Response().Write("<html><body>");
        context.get_Response().Write("<p>ABC Handler</p>\n");
        context.get_Response().Write("</body></html>");
    } //ProcessRequest

    /** @property 
     */
    public boolean get_IsReusable()
    {
        return true;
    } //get_IsReusable
} //abc

// Class definition for xyz.aspx handler.
public class xyz implements IHttpHandler
{
    public void ProcessRequest(HttpContext
 context)
    {
        context.get_Response().Write("<html><body>");
        context.get_Response().Write("<p>XYZ Handler</p>\n");
        context.get_Response().Write("</body></html>");
    } //ProcessRequest

    /** @property 
     */
    public boolean get_IsReusable()
    {
        return true;
    } //get_IsReusable
} //xyz

/*
______________________________________________________________

To use the handler factory, use the following lines in a 
Web.config file.

<configuration>
   <system.web>
      <httpHandlers>
         <add verb="*" path="abc.aspx" type="test.MyFactory
,
            HandlerFactoryTest" />
         <add verb="*" path="xyz.aspx" type="test.MyFactory
,
            HandlerFactoryTest" />
      </httpHandlers>     
   </system.web>
</configuration>
*/

// Name this JScript file HandlerFactoryTest.js and compile it with
 
// the command line: jsc /t:library /r:System.Web.dll HandlerFactoryTest.js.
// Copy HandlerFactoryTest.dll to your bin directory.
import System
import System.Web

package test{
    
    // Factory class that creates a handler object based on request
 
    // for either abc.aspx or xyz.aspx : specified in web.config.
    class MyFactory implements IHttpHandlerFactory{
        
        function IHttpHandlerFactory.GetHandler(context : HttpContext,
 requestType : String, url : String, pathTranslated : String) : IHttpHandler{

            var fname : String = url.Substring(url.LastIndexOf(Char("/"))
 + 1)
            var cname : String = fname.Substring(0, fname.IndexOf(Char(".")))
            var className : String = "test." + cname

            var h : Object = null

            try{// to create the handler object.
                // Create by calling class abc or class xyz.
                h = Activator.CreateInstance(Type.GetType(className))
            }catch(e : Exception){
                throw new HttpException("Factory couldn't
 create instance of type " + className, e)
            }
            return IHttpHandler(h)
        }

        // Must override this class.
        function IHttpHandlerFactory.ReleaseHandler(handler :
 IHttpHandler){
        }
        
    }
    
    
    // Class definition for abc.aspx handler.
    class abc implements IHttpHandler{
        
        function IHttpHandler.ProcessRequest(context : HttpContext){
            context.Response.Write("<html><body>")
            context.Response.Write("<p>ABC Handler</p>\r\n")
            context.Response.Write("</body></html>")
        }        
        
        function get IHttpHandler.IsReusable()
 : Boolean{
            return true
        }
    }
     
    // Class definition for xyz.aspx handler.
    class xyz implements IHttpHandler{
        
        function IHttpHandler.ProcessRequest(context : HttpContext){
            context.Response.Write("<html><body>")
            context.Response.Write("<p>XYZ Handler</p>\r\n")
            context.Response.Write("</body></html>")
        }
        
        
        function get IHttpHandler.IsReusable()
 : Boolean{
            return true
        }
    }
}

//______________________________________________________________
//
//To use the above handler factory, use the following lines in a
//Web.config file. (remove the comment markers)
//
//<configuration>
//   <system.web>
//      <httpHandlers>
//         <add verb="*" path="abc.aspx" type="test.MyFactory
,HandlerFactoryTest"
 />
//         <add verb="*" path="xyz.aspx" type="test.MyFactory
,HandlerFactoryTest"
 />
//      </httpHandlers>
//   </system.web>
//</configuration>


この例の 2 番目の部分では、Web.config の抜粋示します上記ハンドラ ファクトリを使用するには、次の行を Web.config ファイル追加します

<configuration> 
  <system.web> 
    <httpHandlers> 
      <add verb="*" path="abc.aspx" type="test.MyFactory,HandlerFactoryTest" />
 
      <add verb="*" path="xyz.aspx" type="test.MyFactory,HandlerFactoryTest" />
 
    </httpHandlers> 
  </system.web>
</configuration> 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

IHttpHandlerFactory.GetHandler メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IHttpHandlerFactory.GetHandler メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS