JScript.NET

From the things I didn’t know department comes JScript.NET.  What is JScript.NET?  In a nutshell, it’s a .NET version of JScript, i.e. a .NET version of JavaScript!  Why should you care about JScript.NET?  Well, here’s a scenario I had recently:

The company I work for uses Nagios to monitor it’s mission critical systems.  One common use is to simulate a user logging into a web application by POSTing credentials to a login form and checking for specific strings in the response.  This usually gives you an end-to-end check that all systems (web server, database server, etc.) related to the app are functioning.

I was asked to investigate how we could monitor one app in particular that couldn’t be checked with the simple tools included with Nagios.  This application was encrypting the user’s password two different ways using JavaScript before submitting it to the server.  To make matters worse, it was using a random key generated by the server each time the login page was opened.

Since I’m primarily a .NET developer and have very little experience with *NIX systems and PERL (most Nagios plug-ins are written in PERL), my approach was to build a simple web page that Nagios could check that would act as a proxy to this particular app.  This still left me with the problem of how to simulate what the browser was doing in JavaScript. 

One solution would be to translate the JavaScript to C#.  Another would be to try to host the Windows scripting engine in my .NET app and invoke the existing scripts as-is.  Or maybe I could write a "classic" ASP page using JScript.  None of these options appealed to me much, so I consulted Google.

I eventually came across JScript.NET.  I knew about J# (Microsoft’s attempt to lure Java programmers to the .NET platform), but what the heck is JScript.NET?  When I create a new project in Visual Studio, there’s no JScript options…

Hidden away in the .NET SDK is jsc.exe, the JScript.NET compiler.  So, now it was just a matter of taking the JavaScript code I wanted to use from C# and compiling it using jsc /t:library <source file> and I had a DLL I could reference and call.  A few minor tweaks were needed, like wrapping stuff in a class, but overall it was pretty painless and it worked!

Not sure if I’ll ever need to do something like this again, but it’s nice to know JScript.NET is there…