Javascript works locally but not on server and Application_BeginRequest not firing, how to solve

Lionsure 2020-08-23 Original by the website

After the website is developed, there is no problem with local debugging, but it cannot be executed normally when uploaded to the server. This is mainly due to the difference between the local computer and server system. Generally speaking, the system version used by personal computers is generally higher than that of the server. Anyone who has done a website knows that the price of rented server that is high configuration has risen sharply. The higher the system version, the higher the hardware configuration. The reason for saving money can only be first, use an earlier version of the system.

 The local debugging of website is not executed by uploading to the server. Usually see more in the methods in javascript and Global(such as Application_BeginRequest). This article mainly discusses these two situations.

 

1. Javascript works locally but not on server

The main reason for this situation is that the javascript code is wrong, so why can it work locally. As mentioned at the beginning of the article, personal computers often use higher versions of operating systems than servers, and higher versions of operating systems(such as Windows 7,10, Windows Server 2008 R2, 2019) have lower requirements for javascript code; the main manifestation is: as long as there is no especially serious problems in javascript code can be executed down, and some trivial minor problems can be ignored directly; while the lower version operating systems(such as XP, Windows Server 2003) have higher requirements or stricter rules for javascript code, as long as the javascript code has a little bit problem, it immediately terminates the execution and returns.

 

Example of javascript works locally but not on server

If you want to remove the space of value of text input box such a simple function, the code is as follows:

<input type="text" id="testid" />

var obj = document.getElementById("testid");
       var val = obj.value.trim();

There is no trim() method to filter spaces in javascript; in Windows 7, 10 and Windows Server 2008 R2, 2019 systems, the error of this method will be ignored. XP and Windows Server 2003 systems find that there is no trim() method, and immediately terminate the execution and return.

 

2. Application_BeginRequest not firing

First, you should check whether the Global.asax file is uploaded to the server. Without it, all methods in Global will not be executed. If there is this file, it is usually due to an error in the program; you can try to output an error, or cache a value in the Application_BeginRequest method, and output the value in the aspx page to see if the cached value is empty. If it is empty, the code is wrong. You can comment some Code testing to find out the wrong code.