我创建了一个自定义AuthorizeAttribute
,如果用户无权查看请求的控制器,则会将其发送到错误页面。MVC Not Loading完整视图
重定向他们是如下代码:
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
据其重定向到~/Shared/Error.vbhtml
,就像它应该;但是,页面只加载我的布局,并且包含标题"Error"
,但不会加载错误页面的任何内容。是
错误页面的内容如下:
@ModelType System.Web.Mvc.HandleErrorInfo
@Code
ViewData("Title") = "Error"
End Code
@ViewBag.ErrorMessage
<h2>
Sorry, an error occurred while processing your request.
</h2>
为什么没有加载“对不起,发生了错误...”的消息,我怎么可以把它做呢?谢谢。
你可能想看看[这里](http://stackoverflow.com/问题/ 5070339/custom-authorize-attribute)和[this](http://stackoverflow.com/questions/4664302/mvc-roleprovider-and-authorize-attribute)链接 – Yasser 2012-08-07 17:41:49
你确定'〜/ Views/Shared/Error.vbhtml'视图正在呈现?有没有其他的观点可以使用?像'Error.cshtml'一样? – 2012-08-07 17:43:24
@Darin:是的,因为当我将result.ViewName =“Error”更改为result.ViewName =“Error1”时,它给我一个错误。 – user1477388 2012-08-07 17:44:22