Monday, June 22, 2015

ASP pages on IIS - Active Server Pages Error 0221 Invalid @ Command Directive

Setting up asp pages that use asp.net code behind pages to handle the requests will require additional steps to be configured on IIS. I had to upgrade one of the sites which had few asp pages.I did not have the option to rewrite the page as aspx page and hence had to host it on the IIS server an asp page.

The site was upgraded to use 4.0 .Net engine and hosted on IIS 8.5. The aspx pages worked as expected,however I stared getting asp error 0221 when I tried to access the asp urls.

Below is the error screenshot.













The asp file has a page directive indicating that the language is c# and that it uses a code behind page aspx.cs to process the requests.









In order to get the asp page with asp.net code behind file to work, I had to indicate that the page will be processed by the asp.net engine. Below are the screenshots of the steps required to get the asp page to be processed by asp.net engine on IIS 8.5.

Open Inetmgr and navigate to Handler Mappings in the features section for the site hosting the asp page with asp.net code behind page.

















Double Click the Handler Mappings features to bring up all the extension mappings. 

















Double Click ASPClassic  to edit the handler.You will notice that the ASPClassic pages are handled by the asp.dll. This makes the asp page not recognize the page directives since the directives are for the asp.net engine.



















Click the ellipses and navigate to the appropriate .Net framework directory and choose the aspnet_isapi.dll as the handler.In my case the site has been built in .Net 4.0 version.


















Note:For applications built on/for 64-Bit servers the aspnet_isapi.dll handler should be from Framework64 folder.




 















Once the asp.net handler has been mapped.Restart IIS and navigate to the asp page and the error should be resolved.Note that when you do the above handler mapping changes, the configuration file for you site will be updated with the new settings.

<system.webServer>
        <handlers>
                <remove name="ASPClassic" />
                <add name="ASPClassic" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="File" requireAccess="Script" preCondition="bitness32" />
        </handlers>
</system.webServer>















The page no long throws the asp error and returns a xml tag as it supposed in my application.
Hope that helps !

No comments: