Exemple #1
0
        public bool TryIdentifyTenant(out object tenantId)
        {
            tenantId = null;
            try
            {
                var context = HttpContext.Current;
                if (context != null)
                {
                    var subdomain = SubDomainSplitter.GetSubDomain(context.Request.Url);
                    // Use this subdomain to get the tenantId from the database. As of now just return subdomain.

                    /*
                     * string tenantConnectionString = ConfigurationManager.ConnectionStrings["TenantManagement"].ConnectionString;
                     * var sqlConnection = new SqlConnection(tenantConnectionString);
                     * var sqlCommand = new SqlCommand("select connectionstring from Tenants where SubDomain=@subdomain", sqlConnection);
                     * sqlConnection.Open();
                     * sqlCommand.Parameters.AddWithValue("@subdomain", subdomain);
                     * var connectionString = sqlCommand.ExecuteScalar().ToString();
                     */

                    tenantId = subdomain;
                }
            }
            catch (HttpException)
            {
                // Happens at app startup in IIS 7.0
            }

            return(tenantId != null);
        }
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            var key = "";

            var subdomain = SubDomainSplitter.GetSubDomain(httpContext.Request.Url);
            var tenants   = HttpCacheWrapper.GetFromSession <List <string> >(key);

            if (tenants != null && tenants.Contains(subdomain))
            {
                return(true);
            }
            else
            {
                {
                    tenants = TenantDataFetcher.FetchTenantList();
                    HttpCacheWrapper.SetInSession(key, tenants);
                    return(tenants.Contains(subdomain));
                }
            }
        }