コード例 #1
0
        protected void Application_BeginRequest()
        {
            string corePath   = "/core";
            string customPath = "/custom";
            Tenant currentTenant;

            string[]       host          = Context.Request.Headers["Host"].Split(':');
            string         path          = Context.Request.Path;
            IPathService   pathService   = DependencyResolver.Current.GetService(typeof(IPathService)) as IPathService;
            ITenantService tenantService = DependencyResolver.Current.GetService(typeof(ITenantService)) as ITenantService;

            if (host.Length == 0)
            {
                return;
            }
            if (path.Length >= 4 && path.ToLower().Substring(0, 4) == "/api")
            {
                return;
            }
            if (path.Length >= 8 && path.ToLower().Substring(0, 4) == "/scripts")
            {
                return;
            }
            if (path.Length >= 8 && path.ToLower().Substring(0, 4) == "/content")
            {
                return;
            }
            currentTenant = tenantService.GetCurrentTenant(host[0]);
            if (currentTenant == null)
            {
                return;
            }
            string redirectPath = pathService.GetRedirectPath(currentTenant.Id, path);

            if (redirectPath != null)
            {
                Context.RewritePath(redirectPath);
                return;
            }
            if (path.ToLower().IndexOf(corePath.ToLower()) >= 0)
            {
                Context.RewritePath("/Goa" + path);
            }
            if (path.ToLower().IndexOf(customPath.ToLower()) >= 0)
            {
                Context.RewritePath("/Goa" + path.Substring(0, customPath.Length) + "/" + currentTenant.Id.ToString() + path.Substring(customPath.Length, path.Length - customPath.Length));
            }
        }