The following example demonstrates how you can create a class that derives from the PageParserFilter class to govern the behavior of the ASP.NET page parser. The CustomPageParserFilter is a parser filter that explicitly rejects code in the page. It does this by overriding the AllowCode property.
Namespace Samples.AspNet.VB
<PermissionSet(SecurityAction.Demand, Unrestricted := true)> _
Public Class CustomPageParserFilter
Inherits PageParserFilter
Public Overrides ReadOnly Property AllowCode() As Boolean
Get
Return False
End Get
End Property
End Class
End Namespace
namespace Samples.AspNet.CS
{
[PermissionSet(SecurityAction.Demand, Unrestricted = true)]
public class CustomPageParserFilter : PageParserFilter
{
public override bool AllowCode
{
get
{
return false;
}
}
}
}
To use the CustomPageParserFilter sample, place the class in your App_Code directory. You must configure the ASP.NET parsers to use the filter in the pages section of your site's Web.config configuration file. The following example configuration file shows the configuration for CustomPageParserFilter. When configured to use a parser filter, the ASP.NET parser throws an exception during the build if it encounters code in a page.
<?xml version="1.0" ?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<pages
pageParserFilterType="Samples.AspNet.CS.CustomPageParserFilter">
</pages>
</system.web>
</configuration>