I have implemented errors handling in ASP.NET MVC site in a way like suggests this post.
With 404 errors all works fine. But how correctly show user friendly screen
In one of my project, I use the code from uvita.
I have ASP.NET MVC2 and I use Active Directory authentication without login page. I have a NoAuth.aspx page that use site master page, integrate the web application layout.
This is the web.config.
The new class CustomAutorizeAttribute
using System.Web.Mvc;
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
base.HandleUnauthorizedRequest(filterContext);
}
else
{
filterContext.Result = new ViewResult { ViewName = "NoAuth"};
}
}
}
and the controller
[CustomAuthorize(Roles = "ADRole")]
public class HomeController : Controller
{
public HomeController()
{
}
}