I created a custom AuthorizeAttribute
which sends users to an error page if they don't have access to view the controller being requested.
The code that redirects them is as follows:
Protected Overrides Sub HandleUnauthorizedRequest(filterContext As AuthorizationContext)
Dim result = New ViewResult()
result.ViewName = "Error"
result.ViewBag.ErrorMessage = "oops, you are not allowed"
filterContext.Result = result
End Sub
It redirects them to ~/Shared/Error.vbhtml
, just like it should; however, the page only loads my layout and includes the header "Error"
but doesn't not load any content of the error page.
The contents of the error page are as follows:
@ModelType System.Web.Mvc.HandleErrorInfo
@Code
ViewData("Title") = "Error"
End Code
@ViewBag.ErrorMessage
<h2>
Sorry, an error occurred while processing your request.
</h2>
Why isn't it loading the "Sorry, an error occurred..." message and how can I make it do so? Thank you.