ASP.NET MVC 4 - Preventing Direct Access to Custom Error Pages

1k Views Asked by At

It won't let me submit with the codes above, had to take a screenshot. As It can be seen above, I'm using customError pages to handle appropriate errors. Everything works as expected, for instance when a user gets an unhandled exception, on my local the URL is changing as expected : http://localhost/SystemAdministration/Error

However, I don't want users to access this page by typing the url to their browser. Whats the best way to restrict direct access to these error pages and only show them when the related error has occured? Thanks

1

There are 1 best solutions below

0
On

You can create a custom action filter to do that. It's explained in ASP.NET MVC Custom Action Filter To Restrict Direct Access To Action Method. Hope this helps