I have a global include.asp file which contains this code:
if SomeCondition then
Response.Clear
Response.Status = "404 Not Found"
Server.Execute "/error404.asp"
Respnse.End
end if
Two other files, content.asp and error404.asp #include this file.
The content file sets SomeCondition to true causing the error page to Server.Execute. However, that same condition will be true inside error page. This creates an infinite loop and I end up with the following error:
Server object error 'ASP 0227 : 80004005'
Server.Execute Failed
/include.asp, line 1111
The call to Server.Execute failed
How can I avoid the infinite loop? I had these workarounds in mind:
A
if SomeCondition then
if GetExecutedFileNameSomehow() <> "error404.asp" then
' ...
end if
end if
But I cannot seem to get the name of error file through code (I have looked inside server variables, all point variables refer to the calling file i.e. content).
B
Use a shared variable e.g. set BeingExecuted = true in content file and check it inside error file but the problem with Server.Execute is that the executed script cannot access calling file’s variables.
Please advice.
You are correct, due to the nature of Server.Execute, the script being called does not know its real origin and I didn’t find any way to find it.
That said, I fear that you’ll have to resort to ugly work arounds, most reliable I can think of is using a Session variable as a “shared variable”.
In include.asp have such code:
The logic is that the Session variable is set right before calling the Execute method. this way when error404.asp is executed and including the same code again, the value of the Session variable will be set and you know to abort the operation thus avoid the endless loop.