I asked this question since no one got an answer, I have got no option but to fall back to less useful Plan B. I am using URL rewriting to prevent direct access to the .aspx page by using
<httpHandlers>
<add verb="*" path="*.aspx" type="System.Web.HttpForbiddenHandler" />
</httpHandlers>
This raises the error “This type of page is not served.”, how can I instead redirect the user to my own custom handler page? Is there some error code which I can use to redirect? I am looking for a web.config solution.
<error statusCode="" redirect="~/notfound.htm" />//What should I put the error code in here?
Deleting the bin folder and rebuilding the solution solved my problem.