3

これは従来の ASP であり、IIS 8.5 で実行されます。

これらの *.asp ファイルへのすべての Http 要求の開始時に、すべての *.asp ページに共通の VBScript を実行する必要があります。

現在#include、すべての *.asp ファイルの先頭にタグを使用しています。実行したいコードを含むファイルを参照します。

これはうまく機能しますが、見苦しく危険です。*.asp ファイルの 1 つに#includeタグがない場合、コードは実行されません。

すべての *.asp ファイル内にコードを記述せずに、すべての *.asp 要求に対してコードを実行する方法はありますか?

In ASP.NET we have the HttpApplication.BeginRequest event. What I'm looking for is something equivalent to that, but in Classic ASP. I need to run some VBScript that is able to access the Classic ASP objects at the beginning of every *.asp request.

Edit: as per @Kul-Tigin request, this is the reason that I want to do it: My *.asp files are encoded in ANSI. But the URL requests comes encoded in UTF-8, which generate problems.

If I do nothing, the ASP engine decodes the url (and query strings) as if they were in ANSI. For instance: a query string ?value=ç will be sent by the browser as ?value=%C3%A7. C3A7 are the bytes for 'ç' encoded in UTF-8. But the ASP engine reads the 2 bytes as 2 separate ANSI chars. So, if I do nothing, the Request.QueryString("value") will be a string with length 2, with the content "ç".

To fix this, I created the following workaround, which WORKS:

Sub Workaround()
    Response.CodePage = 65001 ' Temporarally set the Response CodePage to UTF-8. Originally it was 1252 (ANSI).
    Dim foo
    foo = Request.QueryString("foo") 'ASP engine uses the Response.CodePage to decode the querystring
    Response.CodePage = 1252 ' Set the Response CodePage back to ANSI.
End Sub
Workaround()

I don't care about the "foo" query string, it may not even exist. I just do that to "touch" the ASP Query String deserialization engine. Aparently it decodes the all the query string values at the first time it is used during the request processing. So, even after setting the CodePage back to 1252, in my previous example, if I read the concrete query string Request.QueryString("value") it will be a length 1 string containing "ç", as intented.

I have put the workaround code in a workaround.inc file, and have included it at the beginning of most of my *.asp files, which solved the problem for now. But there are more than a thousand *.asp files, and more yet to be developed. It's impossible to make sure all of them are including the workaround.inc, that's why I wanted to run the code for all *.asp requests regardless of an include tag.

I appreciate your concern for my problem. If you can present a better solution I would be really happy. Thank you!

4

2 に答える 2

0

簡単にするために、ページ基準に基づいて他のファイルを #include できる一般的な #include を使用します。

于 2016-11-29T12:03:37.793 に答える