コード例 #1
0
        /// <summary>
        /// SPA request event method responsible for determining the domain and culture of <paramref name="request"/>.
        /// </summary>
        /// <param name="request">The current SPA request.</param>
        protected virtual void FindDomainAndCulture(SpaRequest request)
        {
            // Find the domain (sets the "Domain" and "CultureInfo" of "request")
            DomainRepository.FindDomain(request, request.Arguments.Uri);

            if (request.Arguments.PageId > 0)
            {
                // If a page ID was specifically specified for the request, it may mean that we're
                // in preview mode or that the "url" parameter isn't specified. In either case, we
                // need to find the assigned domains of the requested node (or it's ancestor) so we
                // can determine the sitenode

                // TODO: Look at the "siteId" parameter as well (may be relevant for virtual content etc.)

                IPublishedContent c = UmbracoContext.Content.GetById(request.Arguments.PageId);

                if (c != null)
                {
                    request.Domain = DomainRepository.DomainForNode(c, null, request.Arguments.QueryString["culture"]);

                    if (request.Domain != null)
                    {
                        request.CultureInfo = request.Domain.Culture;
                    }
                }
            }

            // Make sure to overwrite the variation context
            VariationContextAccessor.VariationContext = new VariationContext(request.CultureInfo.Name);
        }