Let’s say you are migrating a Classic ASP site to .net core - because you really should! And let’s say you can’t migrate all the pages at once, but you want the new site to be up and running as soon as possible. If so, you are going to need to find a way to run those classic asp pages in the new site…

A .net Core web site arranges all static content (mostly front end resources like css and js) in the wwwroot folder in the project directory. This gets copied when the site is published (using the dotnet publish command). When the site is published, a web.config file is also created, it doesn’t do much by default, mostly just tells IIS to let the aspnetcore dll handler (and kestrel) do all the work. So it’s here we need to add a handler to let IIS process classic asp pages.

Edit the web.config file in \bin\Debug\netcoreapp2.1\publish\ - the system.webserver section will probably look like this…

    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\YourWebSite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>

So, we need to add a rewrite rule to tell IIS where to direct .asp requests to and then a handler to deal with it.

Now, there is already a .asp handler installed (named ASPClassic) but it doesn’t appear to be inherited, I tried adjusting inheritInChildApplications in the location element, but that didn’t seem to work.

The config I suggest here, while not pretty, does work. You will need URLRewrite installed for this as it’s not part of the IIS install, but it’s so useful, it’s likely it’s already there.

    <system.webServer>
      <rewrite>
        <rules>
          <rule name="wwwroot-classicasp" stopProcessing="true">
            <match url="([\S]+[.](asp))" />
            <action type="Rewrite" url="wwwroot/{R:1}" />
          </rule>
        </rules>
      </rewrite>
      <handlers>
        <add name="ASPClassic2" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="File" />
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\YourWebSite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>

Note the new rewrite rule called wwwroot-classicasp, this makes sure the request goes to the right location and the resulting file processed by the ASPClassic2 handler.

There’s still the issue of session state, that’s to be covered in another post…