Example #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                //Tiny optimization.
                //Many times, the vanity url route handler (VanityRoute) would have already loaded the account.
                //  If so, do not load again.

                var account = HttpContext.Items[ContextKeys.RequestedAccount] as Account;

                //If account isn't null and is the same as User.Identity.Name, don't load again.
                //Otherwise Load.
                this.LoggedInAccount = (account != null && account.Username == HttpContext.User.Identity.Name) ?
                                       account : DbContext.Account.Where(u => u.Username == HttpContext.User.Identity.Name).SingleOrDefault();
            }

            //Set Tenant.Id.
            var host = Request.Headers["host"];

            if (!host.Contains("http://"))
            {
                host = "http://" + host;
            }
            var uri = new Uri(host);

            var domain = uri.Host;

            var tenants = m.Tenant.GetAll();

            this.Tenant = tenants.Single(t => t.DomainName == uri.Host);

            base.OnActionExecuting(filterContext);
        }