Search code examples
asp-classicsession-variables

Classic ASP page loading twice per request


I have this very straight forward and simple script in classic ASP using Jscript as the scripting language:

var counter_value = Session.Contents.Item("counter") || 0;

Response.Write("old:" + counter_value);

Session.Contents("counter") = counter_value + 1;

Response.Write("<br/>");

counter_value = Session.Contents.Item("counter");

Response.Write("new: " + counter_value);

When this script is run in the browser for the first time I get this output:

old: 0
new: 1

But when I refresh the page in the browser, I get an unexpected result:

old: 2
new: 3

Why is this happening?


Solution

  • Found out that the problem comes from the page being executed twice per request Because of a rule in url-rewrite.

    The rule states that all requests should be rewritten to index.asp, so when the browser sends a request, the content of index.asp gets returned in the response.

    The same thing happens again when the browser automatically asks for a favicon.ico image.