Getting Classic ASP to work in .js files under IIS 7

Posted by Abdullah Ahmed on Server Fault See other posts from Server Fault or by Abdullah Ahmed
Published on 2010-11-09T13:28:02Z Indexed on 2011/02/11 23:27 UTC
Read the original article Hit count: 304

Filed under:
|
|
|

I am moving a clients classic asp webapp to a new IIS7 based server. The site contains some .js files which have javascript but also classic asp in <% %> tags which contains a bunch of conditional statements designed to spit out pieces of javascript based on session state variables. Here's a brief example of what the file could be like....

var arrHOFFSET = -1;
var arrLeft ="<";
var arrRight = ">";


<% If ((Session("dashInv") = "True") And ((Session("systemLevelStaff") = "4") Or (Session("systemLevelCompany") = "4"))) Then  %>
    addMainItem("/MgmtTools/WelcomeInventory.asp?wherefrom=salesMan","",81,"center","","",0,0,"","","","","");
<% Else %>
    <% If (Session("dashInv") = "False") And ((Session("systemLevelStaff") = "4") Or (Session("systemLevelCompany") = "4")) Then %>
    <% Else %>
        addMainItem("/calendar/welcome.asp","",81,"center","","",0,0,"","","","","");
    <% End If %>
<% End If %>

defineSubmenuProperties(135,"center","center",-3,0,"","","","","","","");

Currently this file (named custom.js for example) will start throwing js errors, because the server doesnt seem to recognize the asp code in it and therefore does not parse it. I know I need to somehow specify that a .js file should also be treated like an .asp file and run through parsing it. However I am not sure how to go about doing this.

Here is what I've tried so far... Under the Server node in IIS under HANDLER MAPPINGS I created a new Script Map with the following settings.

Request Path: *.js Executable: C:\Windows\System32\inetsrv\asp.dll Name: ASPClassicInJSFiles Mapping: Invoke Handler only if request is mapped to : File Verbs: All verbs Access: Script

I also created a similar handler under the site node itself.

Under MIME Types .js is defined as application/x-javascript

None of these work. If I simply rename the file to have .asp extension then things work, however this app is poorly coded and has literally 100's of files with the .js files included in them under various names and locations, so rename, search and replace is the last option I have.

© Server Fault or respective owner

Related posts about iis7

Related posts about JavaScript