The code below isn't exactly what you need, but this is how I am handling unhandled Exceptions. You could alter this to route differently based on status code or exception type. (This is from Global.asax)
protected void Application_Error(object sender, EventArgs e)
{
var ex = Server.GetLastError().GetBaseException();
Server.ClearError();
var routeData = new RouteData();
routeData.Values.Add("controller", "Error");
routeData.Values.Add("action", "Global");
int status = 0;
if (ex.GetType() == typeof(HttpException))
{
var httpException = (HttpException)ex;
var code = httpException.GetHttpCode();
status = code;
}
else
{
status = 500;
}
//Create a new error based off the exception and the error status.
NameSpace.Models.ErrorModel Error = new ErrorModel(status, ex);
string innerException = "";
if (ex.InnerException != null)
{
innerException = "\n Inner Ex: " + ex.InnerException.StackTrace;
}
log.Error("Error Id: " + Error.ErrorId + " Error: " + ex.Message + ". Stack Trace: " + ex.StackTrace + innerException);
routeData.Values.Add("error", Error);
IController errorController = new NameSpace.Controllers.ErrorController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
Update: Apologies, I did not read your post completely. If you were to perform LDAP authentication within your application you could leverage the above code to catch and handle the error with a controller. Unfortunately, I cannot provide direct guidance on your issue above.