LoginSignup
1
2

More than 5 years have passed since last update.

Classic ASPの組み込みオブジェクト(Response)を差し替えた話

Last updated at Posted at 2016-02-09

この記事ではWindows Server 2012 R2 IIS8.5の環境で動作確認をしています。
ASP自体は古い技術なため今動いている環境なら問題なく動くと思います。

差し替える際の注意点としては全てのメソッド、プロパティを実装し、ドキュメント化されてないメソッド等も実装しないとエラーになってしまう可能性があります。(使わなければエラーになりませんが)

実装方法

  1. JScriptのブロック側でオリジナルのResponseオブジェクトを別名の変数に入れます。
  2. VBScriptのブロック側でクラスを定義します。Responseオブジェクトのメソッド等を実装します。
  3. VBScriptのブロックでResponseという名前の変数を用意して定義したクラスをNewします。

サンプルコード

ResponseVer2.asp
<script language="JScript" runat="server">
var jResponse_asp_original = Response;
</script>
<%
Class ClsResponse_Ver2
    Public Property Let Buffer(ByVal Val)
        jResponse_asp_original.Buffer = Val
    End Property
    Public Property Get Buffer()
        Buffer = jResponse_asp_original.Buffer
    End Property
    Public Property Let CacheControl(ByVal Val)
        jResponse_asp_original.CacheControl = Val
    End Property
    Public Property Get CacheControl()
        CacheControl = jResponse_asp_original.CacheControl
    End Property
    Public Property Let Charset(ByVal Val)
        jResponse_asp_original.Charset = Val
    End Property
    Public Property Get Charset()
        Charset = jResponse_asp_original.Charset
    End Property
    Public Property Let CodePage(ByVal Val)
        jResponse_asp_original.CodePage = Val
    End Property
    Public Property Get CodePage()
        CodePage = jResponse_asp_original.CodePage
    End Property
    Public Property Let ContentType(ByVal Val)
        jResponse_asp_original.ContentType = Val
    End Property
    Public Property Get ContentType()
        ContentType = jResponse_asp_original.ContentType
    End Property
    Public Property Get Cookies(ByVal Val)
        Set Cookies = jResponse_asp_original.Cookies(Val)
    End Property
    Public Property Let Cookies(ByVal Index, ByVal Val)
        jResponse_asp_original.Cookies(Index) = Val
    End Property
    Public Property Let Expires(ByVal Val)
        jResponse_asp_original.Expires = Val
    End Property
    Public Property Get Expires()
        Expires = jResponse_asp_original.Expires
    End Property
    Public Property Let ExpiresAbsolute(ByVal Val)
        jResponse_asp_original.ExpiresAbsolute = Val
    End Property
    Public Property Get ExpiresAbsolute()
        ExpiresAbsolute = jResponse_asp_original.ExpiresAbsolute
    End Property
    Public Property Let IsClientConnected(ByVal Val)
        jResponse_asp_original.IsClientConnected = Val
    End Property
    Public Property Get IsClientConnected()
        IsClientConnected = jResponse_asp_original.IsClientConnected
    End Property
    Public Property Let LCID(ByVal Val)
        jResponse_asp_original.LCID = Val
    End Property
    Public Property Get LCID()
        LCID = jResponse_asp_original.LCID
    End Property
    Public Property Let PICS(ByVal Val)
        jResponse_asp_original.PICS = Val
    End Property
    Public Property Get PICS()
        PICS = jResponse_asp_original.PICS
    End Property
    Public Property Let Status(ByVal Val)
        jResponse_asp_original.Status = Val
    End Property
    Public Property Get Status()
        Status = jResponse_asp_original.Status
    End Property
    Sub AddHeader(ByVal name, ByVal value)
        Call jResponse_asp_original.AddHeader(name, value)
    End Sub
    Sub AppendToLog(ByVal Val)
        Call jResponse_asp_original.AppendToLog(Val)
    End Sub
    Sub BinaryWrite(ByVal Val)
        Call jResponse_asp_original.BinaryWrite(Val)
    End Sub
    Sub Clear()
        Call jResponse_asp_original.Clear
    End Sub
    Sub [End]()
        Call jResponse_asp_original.End
    End Sub
    Sub Flush()
        Call jResponse_asp_original.Flush
    End Sub
    Sub Redirect(ByVal Val)
        Call jResponse_asp_original.Redirect(Val)
    End Sub
    Sub Write(ByVal Val)
        jResponse_asp_original.Write Val
    End Sub
    Sub WriteBlock(ByVal Val)
        jResponse_asp_original.WriteBlock Val
    End Sub
End Class
Dim Response
Set Response = New ClsResponse_Ver2
%>

サンプルコード説明

サンプルは内部処理を何も変更していません。変更する場合は各メソッドやプロパティのロジックを好きなようにいじればOKです。
何も処理させたくなければ中のロジックを書かなければいいだけです。

CookiesやWriteBlockの実装

WriteBlockはドキュメント化されてないものです。差し替えた際にエラーとなりこのメソッドの存在を知りました。
<% %> このブロックの外でhtmlを書いた場合に呼ばれるメソッドかと思います。
Cookiesは最初単純にGetとSetのプロパティにしましたが上手く動かず、クッキー名を引数にもらうタイプのプロパティにしてあります。

最後に

この差し替え方法を使えば、他の組み込みオブジェクトの差し替えも可能になると思います。
HTMLEncodeやURLEncodeを今の時代に合うものに差し替えたり
Sessionをべつのもので持つような事も出来るかもしれません。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2