MVC: Error Page implementation

Simple error page implementation…


protected void Application_Error(object sender, EventArgs e)
            var httpContext = ((MvcApplication)sender).Context;
            var currentController = " ";
            var currentAction = " ";
            var currentRouteData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));

            if (currentRouteData != null)
                if (currentRouteData.Values["controller"] != null && !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
                    currentController = currentRouteData.Values["controller"].ToString();

                if (currentRouteData.Values["action"] != null && !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
                    currentAction = currentRouteData.Values["action"].ToString();

            var ex = Server.GetLastError();
            //var controller = new ErrorController();
            var routeData = new RouteData();
            var action = "GenericError";

            if (ex is HttpException)
                var httpEx = ex as HttpException;

                switch (httpEx.GetHttpCode())
                    case 404:
                        action = "NotFound";

                    // others if any

            httpContext.Response.StatusCode = ex is HttpException ? ((HttpException)ex).GetHttpCode() : 500;
            httpContext.Response.TrySkipIisCustomErrors = true;

            routeData.Values["controller"] = "Error";
            routeData.Values["action"] = action;
            routeData.Values["exception"] = new HandleErrorInfo(ex, currentController, currentAction);
            IController errormanagerController = new ErrorController();
            HttpContextWrapper wrapper = new HttpContextWrapper(httpContext);
            var rc = new RequestContext(wrapper, routeData);



public class ErrorController : Controller
        // GET: /Error/

        public ActionResult Index()
            return RedirectToAction("GenericError", new HandleErrorInfo(new HttpException(403, "Dont allow access the error pages"), "ErrorController", "Index"));

        public ViewResult GenericError(HandleErrorInfo exception)
            return View("Error", exception);

        public ViewResult NotFound(HandleErrorInfo exception)
            ViewBag.Title = "Page Not Found";
            return View("Error", exception);


@model System.Web.Mvc.HandleErrorInfo
    ViewBag.Title = ViewBag.Title ?? "Internal Server Error";
<div class="list-header clearfix">
    <span>Error : @ViewBag.Title</span>
<div class="list-sfs-holder">
    <div class="alert alert-error">
        An unexpected error has occurred. Please contact the system administrator.
    @if (Model != null && HttpContext.Current.IsDebuggingEnabled)
                <b>Exception:</b> @Model.Exception.Message<br />
                <b>Controller:</b> @Model.ControllerName<br />
                <b>Action:</b> @Model.ActionName
            <div style="overflow: scroll">


    <customErrors mode="Off" />

End. (:



ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.


  1. Getting Started with ASP.NET SignalR 2.0 (8 Tutorials)

    What is SignalR 2.0 and how to get started adding real-time functionality to a web application.

  2. Hubs API (6 Tutorials)

    This chapter contains information on using Hubs, the higher-level of the two communication paradigms used by SignalR

  3. Security (3 Tutorials)

    This chapter contains information on using authorization in SignalR.

  4. Performance and Scaling (5 Tutorials)

    This chapter contains information on performance and scaling in SignalR.

  5. Troubleshooting and Debugging (1 Tutorials)

    This chapter contains information on finding and fixing issues with SignalR applications.

  6. Extensibility (1 Tutorials)

    Extensibility and dependency injection n SignalR.



Windows Sysinternals

Sysinternals web site was created in 1996 by Mark Russinovich and Bryce Cogswell to host their advanced system utilities and technical information. Whether you’re an IT Pro or a developer, you’ll find Sysinternals utilities to help you manage, troubleshoot and diagnose your Windows systems and applications.

Get up to speed fast!



How do I view the SQL generated by the Entity Framework?

How do I view the SQL generated by the entity framework?

var result = from x in appEntities
             where = 32
             select x;

var sql = ((System.Data.Objects.ObjectQuery)result).ToTraceString();


I create a extension…

public static class IQueryableExtension
     public static String ToTraceSQL(this IQueryable obj) 
         return ((System.Data.Objects.ObjectQuery)obj).ToTraceString();

Using this:

var iQuerableResult = dataBase.BiServico.Take(10);
string myResustSQL = iQuerableResult.ToTraceSQL();

Shazan! =)

hope I have helped!