示例#1
0
 /// <summary>
 /// CTOR finally called by injection CTOR. Good to be used instantiating with DI.
 /// </summary>
 /// <param name="organizationKey"></param>
 /// <param name="organizationContextResolver"></param>
 /// <param name="siteList"></param>
 public SiteContext(string organizationKey, OrganizationContextResolver organizationContextResolver, SiteList siteList)
 {
     SiteList = siteList;
     OrganizationContextResolver = organizationContextResolver;
     // copies the resolved OrganizationContext properties to this siteContext
     Resolve(this, organizationKey);
 }
示例#2
0
        private SiteContext Resolve(SiteContext siteContext, string organizationKey)
        {
            var siteSettings = SiteList.FirstOrDefault(sl => sl.OrganizationKey == (organizationKey ?? string.Empty));

            if (siteSettings == null)
            {
                return(null);
            }

            OrganizationContextResolver.CopyContextTo(siteContext, organizationKey); // shallow-copy all OrganizationContext properties
            siteContext.HostName           = siteSettings.HostName;
            siteContext.UrlSegmentValue    = siteSettings.UrlSegmentValue;
            siteContext.FolderName         = siteSettings.FolderName;
            siteContext.IdentityCookieName = siteSettings.IdentityCookieName;
            siteContext.SessionName        = siteSettings.SessionName;
            siteContext.HideInMenu         = siteSettings.HideInMenu;

            return(siteContext);
        }
示例#3
0
        /// <summary>
        /// Resolves the organization key from the <see cref="HttpRequest"/>.
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="siteList"><see cref="SiteList"/></param>
        /// <returns>Returns the organization key, if found in the <see cref="SiteList"/>, else null.</returns>
        public static string ResolveOrganizationKey(HttpContext httpContext, SiteList siteList)
        {
            if (httpContext == null)
            {
                return(null);
            }

            var request = httpContext.Request;
            // used if site is identified by host name (and port)
            var host = request.Host.ToString();
            // first segment:  /
            // second segment: organization/
            // third segment:  account/
            var uri = new Uri(request.GetDisplayUrl());
            // used if site is identified by the first segment of the URI
            var siteSegment = uri.Segments.Length > 1 ? uri.Segments[1].TrimEnd('/') : string.Empty;

            foreach (var site in siteList)
            {
                if (!string.IsNullOrEmpty(site.HostName))
                {
                    if (site.HostName == host && (string.IsNullOrEmpty(site.UrlSegmentValue)))
                    {
                        return(site.OrganizationKey);
                    }
                }
                else
                {
                    if (site.UrlSegmentValue == siteSegment)
                    {
                        return(site.OrganizationKey);
                    }
                }
            }

            return(null);
        }
示例#4
0
 /// <summary>
 /// Mainly helper CTOR called by injection CTOR.
 /// </summary>
 /// <param name="httpContext"></param>
 /// <param name="organizationContextResolver"></param>
 /// <param name="siteList"></param>
 public SiteContext(HttpContext httpContext, OrganizationContextResolver organizationContextResolver,
                    SiteList siteList) :
     this(ResolveOrganizationKey(httpContext, siteList), organizationContextResolver, siteList)
 {
     SetMostRecentOrganizationCookie(httpContext, base.OrganizationKey);
 }
示例#5
0
 /// <summary>
 /// CTOR for dependency injection.
 /// </summary>
 /// <param name="httpContextAccessor"></param>
 /// <param name="organizationContextResolver"></param>
 /// <param name="siteList"></param>
 public SiteContext(IHttpContextAccessor httpContextAccessor, OrganizationContextResolver organizationContextResolver, SiteList siteList) :
     this(httpContextAccessor?.HttpContext, organizationContextResolver, siteList)
 {
 }