示例#1
0
        public void GetLocaleFromContext()
        {
            var context = httpContextFactory.GetHttpContext();
            var tenant  = appContext.CurrentTenant;

            // Set the current culture
            var culture = contextUtilities.GetLocaleFromContext(context, tenant.DefaultLocale);

            Thread.CurrentThread.CurrentUICulture = culture;
            Thread.CurrentThread.CurrentCulture   = culture;
        }
        public TenantInitializer(
            IContextUtilities contextUtilities,
            IHttpContextFactory httpContextFactory,
            IApplicationContext appContext
            )
        {
            if (contextUtilities == null)
                throw new ArgumentNullException("contextUtilities");
            if (httpContextFactory == null)
                throw new ArgumentNullException("httpContextFactory");
            if (appContext == null)
                throw new ArgumentNullException("appContext");

            // Lookup the current tenant and put it into ambient context on the current request
            var context = httpContextFactory.GetHttpContext();
            appContext.CurrentTenant = contextUtilities.GetTenantFromContext(context);
        }
示例#3
0
        public TenantInitializer(
            IContextUtilities contextUtilities,
            IHttpContextFactory httpContextFactory,
            IApplicationContext appContext
            )
        {
            if (contextUtilities == null)
            {
                throw new ArgumentNullException("contextUtilities");
            }
            if (httpContextFactory == null)
            {
                throw new ArgumentNullException("httpContextFactory");
            }
            if (appContext == null)
            {
                throw new ArgumentNullException("appContext");
            }

            // Lookup the current tenant and put it into ambient context on the current request
            var context = httpContextFactory.GetHttpContext();

            appContext.CurrentTenant = contextUtilities.GetTenantFromContext(context);
        }
        public void ProcessUnhandledError()
        {
            var context = httpContextFactory.GetHttpContext();

            // Avoid IIS7 getting in the middle
            context.Response.TrySkipIisCustomErrors = true;

            if (!context.IsDebuggingEnabled)
            {
                var exception     = context.Server.GetLastError();
                var httpException = exception as HttpException;

                context.Response.Clear();
                context.Server.ClearError();
                var routeData = new RouteData();
                routeData.Values["controller"] = "System";
                routeData.Values["action"]     = "Status500";
                routeData.Values["exception"]  = exception;
                context.Response.StatusCode    = (int)HttpStatusCode.InternalServerError;
                if (httpException != null)
                {
                    context.Response.StatusCode = httpException.GetHttpCode();
                    switch (context.Response.StatusCode)
                    {
                    //case 403:
                    //    routeData.Values["action"] = "Status403";
                    //    break;
                    case 404:
                        routeData.Values["action"] = "Status404";
                        break;
                    }
                }
                var requestContext = new RequestContext(context, routeData);
                systemController.Execute(requestContext);
            }
        }