using System.Linq; using System.Web.Mvc; using System.Configuration; using System.Web.Routing; using Neo.LegitimateLicences.Web.FrameworkExtensions; using System; using Sentry; using Sentry.AspNet; using System.Web; using System.Collections.Generic; using Neo.Legitimate.Web.DBUp; namespace Neo.LegitimateLicences.Web { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { //filters.Add(new HandleErrorAttribute()); // Use the fixed HandleErrorAttributeWithHealthMonitoring ////filters.Add(new HandleErrorAttributeWithHealthMonitoring()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" }); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); var ignorePaths = ConfigurationManager.AppSettings["ExternalRouteIgnores"]; if (ignorePaths != null) { foreach (var s in ignorePaths.Split(',').Where(s => !string.IsNullOrEmpty(s))) { routes.IgnoreRoute(s); } } routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Default", id = UrlParameter.Optional } // Parameter defaults ); } private IDisposable _sentry; protected void Application_Start() { ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder()); ModelBinders.Binders.Add(typeof(decimal?), new DecimalModelBinder()); //ViewEngines.Engines.Add(new CustomViewEngine()); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["SentryDsn"])) { _sentry = SentrySdk.Init(o => { o.AddAspNet(); o.Dsn = ConfigurationManager.AppSettings["SentryDsn"]; o.Debug = true; o.TracesSampleRate = 1.0; o.AddEntityFramework(); }); } DatabaseUpdator.UpdateDB(); } protected void Application_Error() { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["SentryDsn"])) { var exception = Server.GetLastError(); SentrySdk.WithScope(scope => { if (HttpContext.Current != null && HttpContext.Current.Profile != null) { scope.User = new Sentry.User { Email = HttpContext.Current.Profile.UserName }; } if (HttpContext.Current != null && HttpContext.Current.Request != null && !string.IsNullOrEmpty(HttpContext.Current.Request.CurrentExecutionFilePath)) { var errorGroup = new List { "{{ default }}", HttpContext.Current.Request.CurrentExecutionFilePath }; scope.SetFingerprint(errorGroup); } SentrySdk.CaptureException(exception); }); } } protected void Application_End() { _sentry?.Dispose(); } protected void Application_BeginRequest() { Context.StartSentryTransaction(); } protected void Application_EndRequest() { Context.FinishSentryTransaction(); } ////protected void Application_EndRequest() ////{ //// //This forces IE8 to display the pages in IE8 Mode and NOT Compatibitlity Mode //// //It's the only way to override the IE > Tools > Compatibility Vie Settings > Display Intranet Sites in Compatibility View option //// //You have to check the file extension as you only want to do this for MVC pages i.e. extensionless. You can't add teh header to services etc. //// if(string.IsNullOrEmpty(Request.CurrentExecutionFilePathExtension)) //// { //// Response.AddHeader("X-UA-Compatible", "IE=EmulateIE8"); //// } ////} } }