Application pages in sharepoint behave like asp.net pages where they may contain inline server code. Wheras site pages are rendered as safe mode parser so there is no problem with these type of pages.
The problem comes with application pages i.e. asp.net pages. SharePoint will not allow any pages to be render which contains in line server code. If you can say here sharepoint shows its limitation towards development. But there is a way to overcome this problem. If you want to render pages with inline server code then you can use <PageParserPath>…</ PageParserPath>.
So, how to use PageParserPath to render pages with inline server code.
Go to the web.config file of SharePoint and search for <SharePoint> tag, within it you can use page parser path like this.
<PageParserPath VirtualPath=”/myFiles/*” CompilationMode=”Always”
AllowServerSideScript=”true” IncludeSubFolders=”true”/>
</PageParserPaths>
So now if you run application pages which contains in line server code then SharePoint will render it successfully.
Now you may add below code to your page:
<script runat=”server”>
protected void Page_Load(Object sender, EventArgs e)
{
Response.Write(“My code”);
}
</script>