Endless runtime for a script that sometimes works

After I execute this code asp scripts quite working.

<!-- #include file="Connection.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
function Page()
{   
    var db = new DBConnection;
    this.DAL = db.retriveDAL("Content");

    var url = new String(Request.ServerVariables("QUERY_STRING")), site = new String(Request.ServerVariables("QUERY_STRING"));
    site = url.slice(4, url.indexOf(":80", 0)) + "/";
    url = url.slice(url.indexOf("80", 0) + 2, url.length).split("/");

    var pageName = url[1], pageID = url[2];

    var xmlhttp = Server.CreateObject("Microsoft.XMLHTTP");

    xmlhttp.open("POST", site+"library/Datastore.asp?page="+pageName + (pageID ? "id=" + pageID : ""), false);
    xmlhttp.send();

    var xml = Server.CreateObject("Microsoft.XMLDOM");
    xml.async = false;

    xml.loadXML(xmlhttp.responseText);

    var xsl = Server.CreateObject("Microsoft.XMLDOM");
    xsl.async = false;
    xsl.load(Server.MapPath("templates/" + pageName + ".xsl"));

    Response.Write(xml.transformNode(xsl));
}
%>

Does anybody know why? There is no reason for it now to work. It also disables any asp script in the website.

EDIT: I just disabled the xmlhttp and re-created the sites and asp works fine. EDIT 2: I just discovered that the Server.Transfer is causing the endless runtime. Any idea why?

Answers


Tip #1:

Build a proper URL. You use

site
 + "library/Datastore.asp?page="
 + pageName
 + (pageID ? "id=" + pageID : "")

but correct is

site
  + "library/Datastore.asp?page="
  + Server.URLEncode(pageName) 
  + (pageID ? "&id=" + Server.URLEncode(pageID) : "")
//-------------^  !!

Tip #2:

Instead of

Response.Write(xml.transformNode(xsl));

use

xml.transformNodeToObject(xsl, Response);

This way you won't run into any output encoding issues.

Tip #3: (From the comments: This turned out as wrong.)

Request.ServerVariables("QUERY_STRING")

already is a string. No need to wrap it in new String(). Apparently, strings that come out of Request.ServerVariables are not JS strings, so constructing a native String object is really necessary here.

Tip #4:

For use on a HTTP server (that is multi-threaded by its very nature), you should be using Msxml2.ServerXMLHTTP instead of Microsoft.XMLHTTP and instead of Microsoft.XMLDOM you should be using MSXML2.FreeThreadedDOMDocument.


Are you calling the script off the same server? If so you will have problem with Session being locked. When a page has Session it locks the Session object for that user until it finishes (or timesout). When you call the second page on the same server it hangs while it waits for the Session lock to be freed (which can't happen as the calling page has it). You end up with the page timing out.

Can be fixed by switching off session for either of the pages.


Need Your Help

how to start 123.exe after pushed save button?

c# add

I have some code in C# it is for saving some data in alterIWnet.ini file so after saved data in alterIWnet.ini file the form gets closed.

How is the Subtype Discriminator used?

c# sql-server subtype discriminator supertype

Suppose I have a supertype table with many subtype tables. I'm interested in making them disjoint subtypes in that the supertype table only points to one of the possible subtype tables per row. On...