If you must add server-side code to an .aspx page within your SharePoint environment, then you will need to explicitly tell SharePoint to allow it on the particular page (you can tell SharePoint to allow it on all pages (*), but this is highly discouraged). In fact, if you are able, you should instead deploy your code as a custom user control .

Anyway, to fix this error, all you need to do is add a line to the web.config file under the virtual directory of the Web application. On your MOSS server, open Inetpub > wwwroot > wss > VirtualDirectories > [WebAppName] > web.config.

Find the tag (it will most likely be an empty tag), and add the following line:

Replace “/default.aspx” with the relative path to your .aspx file that has the server-side code. Save the web.config file (this will cause an IIS reset, just FYI). That’s it. Refresh your page and it should be working.