2

We are upgrading an ASP Classic website (actually, a virtual directory under a larger website) to ASP.NET 3.5. There will be some legacy directories that remain ASP Classic. Other than that, every .asp file will be replaced by an .aspx file in the same location in the directory hierarchy. We would like not to break old links coming into the site from elsewhere. The website is hosted on IIS 6 (and we have no control over this).

My idea was, in IIS, to replace the usual handler for .asp files, asp.dll, with aspnet_isapi.dll. First question: If I do that, will requests for .asp files then be routed through any custom HTTP modules I create and register in web.config?

Then I would create an HTTP module hooked into BeginRequest that would test whether a request's path (before any querystring) ends in .asp. If so, it would check whether the physical file exists. If not, then I'll use HttpContext.RewritePath to append the "x" to the ".asp". Otherwise, if the .asp file DOES exist, I'll use HttpContext.RemapHandler to switch the handler back to asp.dll so that the file will be processed as the ASP Classic file that it is.

Second question: Will this work? Third question: What do I use as the argument to the RemapHandler method? How do I acquire a reference to an instance of the ASP Classic handler? (If I knew the answer to the third question, I'd have just tried all this on my own!)

UPDATE: OK, I did try it out myself, except that I renamed the remaining .asp files so that their extension is .aspc (ASP Classic), and in IIS I assigned the old asp.dll as their handler. Then, instead of checking whether the .asp file requested exists and remapping to the ASP Classic handler if so, I checked instead whether a file in the corresponding physical location except with the extension .aspc exists. If so, I rewrite the URL to append the "c". This worked! Therefore, the answer to my first question, above, is "yes", and the answer to my second question is "yes, pretty much, except that the part about remapping the handler is unknown". But it would be preferable not to have to change the extensions on all my legacy .asp files, so I am left with one question: Will the original RemapHandler approach work and, if so, what is its argument?

Green Grasso Holm
  • 468
  • 1
  • 4
  • 18
  • Wouldn't a custom error page for a 404 error work? Otherwise, did you check this previous SO post : http://stackoverflow.com/questions/1572746/mapping-classic-asp-pages-to-net-in-iis – AardVark71 Feb 09 '13 at 08:32
  • Thanks for the pointer to that previous discussion. I hadn't come across it before. I added the suggested BuildProvider and httpHandler code to web.config. It is now trying to parse the page, but on every line with a VBScript comment (everything to the right of a single quote) it is giving me "Newline in constant" and "Too many characters in character literal", as though it now thinks that a single quote should be a string delimiter rather than a comment marker. – Green Grasso Holm Feb 11 '13 at 12:57
  • I added **<%@ LANGUAGE="VBScript"%>** to the top of one of my .asp files and requested it again. That got rid of the previous error, but now it has also started acting as though I'd added **Option Explicit** even though I didn't. It started flagging assignment statements with "Declaration expected." THEN I declared the first couple of variables, after which it accepted them, and then errored out on a Set statement: "BC30807: 'Let' and 'Set' assignment statements are no longer supported." Any ideas what's going on? – Green Grasso Holm Feb 11 '13 at 13:10
  • Oh, it's also flagging my Dim statements as "BC42020: Variable declaration without an 'As' clause; type of Object assumed." Since this is VBScript, an untyped language, I am really curious what's going on. – Green Grasso Holm Feb 11 '13 at 13:13
  • By the way, I don't know if it makes any difference, but all these supposed errors that are being flagged so far are in #include files that are being included in the main page. – Green Grasso Holm Feb 11 '13 at 13:15

1 Answers1

0

Did you know, that you could handle this quite easily using the web.config file and redirect rules in IIS?

You need to activate the URL Rewrite2 module described here. This is a really nice feature of IIS, to solve routing problems, see here also for some examples.

Looking at your case, I would do something along the lines of this:

<rule name="execute classic asp if file exists" stopProcessing="true">
  <match url="(\w+\.asp)$" />
  <conditions>
    <add input="C:\Path\To\Your\WebApp\{R:1}.asp" matchType="IsFile" />
  </conditions>
  <action type="Rewrite" url="{R:1}c" appendQueryString="true" />
</rule>
<rule name="execute dotnet otherwise" stopProcessing="true">
  <match url="(\w+\.asp)$" />
  <action type="Rewrite" url="{R:1}x" appendQueryString="true" />
</rule>

I'm not sure if all RegExes here would work for you, but its meant as a start to experiment. The reason to explicitely write C:\Path\To\Your\WebApp\ is, that I didn't find a way to get the base path of the web app as a parameter.

gpinkas
  • 2,291
  • 2
  • 33
  • 49