This is classic ASP, running on IIS 8.5.
I need to run some VBScript that should be common to all my *.asp pages at the beginning of every Http request to those *.asp files.
Currently I am using a #include
tag at the top of each and every *.asp file. I reference a file that contains the code that I want to run.
It does the trick, but it's ugly and dangerous: if one of the *.asp files happens to miss the #include
tag, the code will not run.
Is there a way to make some code run for every *.asp request, without having to write code inside every *.asp file?
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!