We have a custom ASP.NET role provider implemented in our website (.net4, IIS 7.5, VS 2010, all pretty stock stuff). My question is how to handle or intercept the role provider redirect when the user is denied access to a page?
Let me be clear. The role provider is working correctly. We created web.config files in various subdirectories of our website that add the appropriate elements/attributes for access. So let's say I try to access a page in a subdir that I don't have a role for... right now, the role provider redirects me to our Login page (presumably coming off the web.config values for our Membership provider as well).
What I want to do, however, is redirect the user to a custom "Access Denied" page of our choosing, not the login page.
Based on many google searches, I tried a few things that simply did not work.
For example, one person suggested adding a custom Application_Error method to the global.asax file. Tried that, it never got hit.
Also tried adding to the customErrors section in web.config:
<error statusCode="401" redirect="AccessDenied.aspx" />
Again, that never worked.
As many debug breakpoints I put in, the best I can tell is that the role provider is doing its thing much earlier in the lifecycle than I can catch and is automatically redirecting to our login page.
Any thoughts on how to intercept this would be greatly appreciated.
Thanks.