142 lines
5.3 KiB
C#
142 lines
5.3 KiB
C#
using System.Data.Entity.Validation;
|
|
using System.Text;
|
|
using EnVisage.Code;
|
|
using EnVisage.Models;
|
|
using NLog;
|
|
using jQuery.DataTables.Mvc;
|
|
using System;
|
|
using System.Data.Entity;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Optimization;
|
|
using System.Web.Routing;
|
|
using System.Web.Helpers;
|
|
using Microsoft.IdentityModel.Claims;
|
|
using System.Linq;
|
|
using DevExpress.XtraReports.Native;
|
|
using Envisage.Code.BLL;
|
|
|
|
namespace EnVisage
|
|
{
|
|
public class MvcApplication : System.Web.HttpApplication
|
|
{
|
|
protected void Application_Start()
|
|
{
|
|
Database.SetInitializer<ApplicationDbContext>(null);
|
|
AreaRegistration.RegisterAllAreas();
|
|
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
|
ModelBinders.Binders.Add(typeof(JQueryDataTablesModel), new JQueryDataTablesModelBinder());
|
|
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;
|
|
MongoMigrationConfig.RunMigration();
|
|
|
|
var jsonFactory = ValueProviderFactories.Factories.FirstOrDefault(x => x.GetType() == typeof(JsonValueProviderFactory));
|
|
if (jsonFactory != null)
|
|
ValueProviderFactories.Factories.Remove(jsonFactory);
|
|
ValueProviderFactories.Factories.Add(new AdvancedJsonValueProviderFactory());
|
|
ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder();
|
|
// NOTE: Register DataSource serializer for XtraReport
|
|
// required for client-server communication
|
|
SerializationService.RegisterSerializer(CustomDataSourceSerializer.Name, new CustomDataSourceSerializer());
|
|
DevExpress.Web.ASPxWebControl.CallbackError += Application_Error;
|
|
}
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
{
|
|
var exception = Server.GetLastError();
|
|
if (exception == null)
|
|
return;
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine(string.Format("{0}: {1}", exception.GetType(), exception.Message));
|
|
sb.AppendLine(exception.StackTrace);
|
|
|
|
var innerCount = 0;
|
|
var innerEx = exception;
|
|
while (innerEx.InnerException != null && innerCount++ < Constants.MAX_INNER_EXCEPTION_LOG_LEVEL)
|
|
{
|
|
if (innerEx.Message != innerEx.InnerException.Message)
|
|
sb.AppendLine("Inner Exception Message: " + exception.InnerException.Message);
|
|
innerEx = innerEx.InnerException;
|
|
}
|
|
if (exception is DbEntityValidationException)
|
|
{
|
|
sb.AppendLine();
|
|
foreach (var validationErrors in ((DbEntityValidationException)exception).EntityValidationErrors)
|
|
{
|
|
|
|
foreach (var validationError in validationErrors.ValidationErrors)
|
|
{
|
|
sb.AppendFormat("Property: {0} Error: {1}", validationError.PropertyName,
|
|
validationError.ErrorMessage);
|
|
|
|
}
|
|
}
|
|
sb.AppendLine(exception.StackTrace);
|
|
}
|
|
if (HttpContext.Current != null)
|
|
{
|
|
try
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine(string.Format("URL: {0}", HttpContext.Current.Request.Url));
|
|
sb.AppendLine(string.Format("Referrer: {0}", HttpContext.Current.Request.UrlReferrer));
|
|
sb.AppendLine(string.Format("QueryString: {0}", HttpContext.Current.Request.QueryString));
|
|
sb.AppendLine(string.Format("UserHostAddress: {0}", HttpContext.Current.Request.UserHostAddress));
|
|
sb.AppendLine(string.Format("UserAgent: {0}", HttpContext.Current.Request.UserAgent));
|
|
if (HttpContext.Current.Request.Form.Count > 0)
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine("Form:");
|
|
foreach (string key in HttpContext.Current.Request.Form.Keys)
|
|
{
|
|
sb.AppendLine(string.Format("{0}: {1}", key, HttpContext.Current.Request.Form[key]));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) //HttpContext.Current.Request could throw exception
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine("Error while handling exception details from HttpContext.Current:");
|
|
sb.AppendLine(ex.ToString());
|
|
}
|
|
}
|
|
var logger = LogManager.GetCurrentClassLogger();
|
|
if (logger != null)
|
|
logger.Fatal(sb.ToString());
|
|
}
|
|
|
|
// SA. ENV-502
|
|
protected void Session_OnStart()
|
|
{
|
|
try
|
|
{
|
|
FileManager mngr = new FileManager(null);
|
|
mngr.EmptyUserTempFolder();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
// SA. ENV-502
|
|
protected void Session_OnEnd()
|
|
{
|
|
try
|
|
{
|
|
using (EnVisageEntities dbContext = new EnVisageEntities())
|
|
{
|
|
FileManager mngr = new FileManager(dbContext);
|
|
// Remove user tempory files
|
|
mngr.EmptyUserTempFolder();
|
|
// Remove user unattached permanent files
|
|
//mngr.DeleteUserUnattachedPermanentFiles();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|