コード例 #1
0
        public SPAlternateUrlInstance(ObjectInstance prototype, SPAlternateUrl alternateUrl)
            : this(prototype)
        {
            if (alternateUrl == null)
            {
                throw new ArgumentNullException("alternateUrl");
            }

            m_alternateUrl = alternateUrl;
        }
 internal static void GetUrls(List<string> urls, SPAlternateUrl url)
 {
     string host = url.Uri.Host.ToLower();
     if (!urls.Contains(host) && // Don't add if we already have it
         !url.Uri.IsLoopback && // Quick check to short circuit the more elaborate checks
         host != Environment.MachineName.ToLower() && // Quick check to short circuit the more elaborate checks
         IsLocalIpAddress(host) && // If the host name points locally then we need to add it
         !IsSharePointServer(host)) // Don't add if it matches an SP server name (handles central admin)
     {
         urls.Add(host);
     }
 }
コード例 #3
0
        internal static void GetUrls(List <string> urls, SPAlternateUrl url)
        {
            string host = url.Uri.Host.ToLower();

            if (!urls.Contains(host) &&                      // Don't add if we already have it
                !url.Uri.IsLoopback &&                       // Quick check to short circuit the more elaborate checks
                host != Environment.MachineName.ToLower() && // Quick check to short circuit the more elaborate checks
                IsLocalIpAddress(host) &&                    // If the host name points locally then we need to add it
                !IsSharePointServer(host))                   // Don't add if it matches an SP server name (handles central admin)
            {
                urls.Add(host);
            }
        }
コード例 #4
0
        private void DeployDefinition(object modelHost, SPWebApplication webApp, AlternateUrlDefinition definition)
        {
            var alternateUrls = webApp.AlternateUrls;

            var url     = definition.Url;
            var urlZone = (SPUrlZone)Enum.Parse(typeof(SPUrlZone), definition.UrlZone);

            var responseUrl = GetCurrentAlternateUrl(webApp, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = responseUrl,
                ObjectType       = typeof(SPAlternateUrl),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (!string.IsNullOrEmpty(url))
            {
                responseUrl = new SPAlternateUrl(url, urlZone);
                alternateUrls.SetResponseUrl(responseUrl);
            }
            else
            {
                alternateUrls.UnsetResponseUrl(urlZone);
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = responseUrl,
                ObjectType       = typeof(SPAlternateUrl),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            alternateUrls.Update();
        }
コード例 #5
0
        private void DeployDefinition(object modelHost, SPWebApplication webApp, AlternateUrlDefinition definition)
        {
            var alternateUrls = webApp.AlternateUrls;

            var url = definition.Url;
            var urlZone = (SPUrlZone)Enum.Parse(typeof(SPUrlZone), definition.UrlZone);

            var responseUrl = GetCurrentAlternateUrl(webApp, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = responseUrl,
                ObjectType = typeof(SPAlternateUrl),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (!string.IsNullOrEmpty(url))
            {
                responseUrl = new SPAlternateUrl(url, urlZone);
                alternateUrls.SetResponseUrl(responseUrl);
            }
            else
            {
                alternateUrls.UnsetResponseUrl(urlZone);
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = responseUrl,
                ObjectType = typeof(SPAlternateUrl),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            alternateUrls.Update();
        }
コード例 #6
0
ファイル: AutoSignin.cs プロジェクト: vairam-svs/spautosignin
        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {
                if (SPContext.Current == null)
                {
                    return;
                }
                if (SPContext.Current.Site == null)
                {
                    return;
                }
                if (SPContext.Current.Site.WebApplication == null)
                {
                    return;
                }

                SPWebApplication app = SPContext.Current.Site.WebApplication;

                SignInConfiguration config = app.GetChild <SignInConfiguration>("SignInConfig");
                if (config == null)
                {
                    throw new NullReferenceException("Config was not found");
                }

                SPAlternateUrl u = app.AlternateUrls[Request.Url];
                if (u == null)
                {
                    throw new NullReferenceException("Could not find " + Request.Url + " in alternate URLs");
                }
                SPUrlZone zone = u.UrlZone;

                string components = Request.Url.GetComponents(UriComponents.Query, UriFormat.SafeUnescaped);

                if (!app.IisSettings.ContainsKey(zone))
                {
                    zone = SPUrlZone.Default;
                }
                //throw new KeyNotFoundException("IIS settings did not have zone " + zone);
                SPIisSettings settings       = app.IisSettings[zone];
                bool          isMappingFound = false;

                IPAddress ipv4 = IpNetworking.GetIP4Address();
                string    targetProvider;
                try
                {
                    KeyValuePair <IPNetwork, string> providerMapping = config.ProviderMappings
                                                                       .Select(kvp => new KeyValuePair <IPNetwork, string>(IPNetwork.Parse(kvp.Key), kvp.Value))
                                                                       .Where(x => IPNetwork.Contains(x.Key, ipv4))
                                                                       .OrderBy(x => x.Key.Cidr)
                                                                       .Last();
                    isMappingFound = true;
                    targetProvider = providerMapping.Value;
                }
                catch
                {
                    isMappingFound = false;
                    targetProvider = null;
                }
                var signinPageMappings = config.SingInPageMappings;
                if (config != null && isMappingFound)
                {
                    foreach (SPAuthenticationProvider provider in settings.ClaimsAuthenticationProviders)
                    {
                        if (string.Compare(provider.DisplayName, targetProvider, true, System.Globalization.CultureInfo.CurrentUICulture) == 0 ||
                            string.Compare(provider.ClaimProviderName, targetProvider, true, System.Globalization.CultureInfo.CurrentUICulture) == 0)
                        {
                            string url = provider.AuthenticationRedirectionUrl.ToString();
                            if (signinPageMappings.ContainsKey(provider.DisplayName))
                            {
                                url = signinPageMappings[provider.DisplayName];
                            }

                            if (provider is SPWindowsAuthenticationProvider)
                            {
                                components = EnsureReturnUrl(components);
                            }

                            SPUtility.Redirect(url, SPRedirectFlags.Default, this.Context, components);
                        }
                    }
                    base.OnLoad(e);
                }
                else
                {
                    string loginPage = string.Empty;
                    if (signinPageMappings.ContainsKey("default"))
                    {
                        loginPage = signinPageMappings["default"];
                    }
                    if (!string.IsNullOrEmpty(loginPage))
                    {
                        SPUtility.Redirect(loginPage, SPRedirectFlags.Default, this.Context, components);
                        base.OnLoad(e);
                    }
                }
            }
        }
コード例 #7
0
        private void ChangeZone()
        {
            if (Zone != SPUrlZone.Internet)
            {
                SPAlternateUrlCollection alternateUrls = WebApplication.AlternateUrls;
                SPAlternateUrl           alternateurl  = new SPAlternateUrl(Url, Zone);
                Uri internetRoot = null;

                try
                {
                    internetRoot = WebApplication.GetResponseUri(Zone);
                }
                catch
                {
                    internetRoot = null;
                }


                try
                {
                    alternateurl = alternateUrls[Url];
                    if (alternateurl == null || alternateurl.UrlZone != SPUrlZone.Internet)
                    {
                        alternateurl = null;
                    }
                }
                catch (Exception ex)
                {
                    alternateurl = null;
                    ex.ToString();
                }

                if (_delete)
                {
                    if (!string.IsNullOrEmpty(Url) && alternateurl != null)
                    {
                        try
                        {
                            alternateUrls.Delete(Url);
                        }
                        catch (Exception ex)
                        {
                            ex.ToString();
                        }
                        finally
                        {
                            alternateUrls.Update();
                        }
                    }
                }
                else
                {
                    try
                    {
                        //No Internet Url defined;
                        if (internetRoot == null)
                        {
                            if (!string.IsNullOrEmpty(Url))
                            {
                                SPAlternateUrl defaultInternet = new SPAlternateUrl(Url, Zone);
                                alternateUrls.SetResponseUrl(defaultInternet);
                            }
                        }
                        // Incoming Urls
                        else
                        {
                            SPAlternateUrl incomingUrl = new SPAlternateUrl(Url, Zone);
                            alternateUrls.Add(incomingUrl);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                    finally
                    {
                        alternateUrls.Update();
                    }
                }
            }
        }
コード例 #8
0
 public static string GetUrlZone(this SPAlternateUrl alternateUrl)
 {
     return(alternateUrl.UrlZone.ToString());
 }
コード例 #9
0
        /// <summary>
        /// Возвращает абсолютный url для веб-приложения 
        /// </summary>
        /// <param name="url"></param>
        /// <param name="web"></param>
        /// <param name="alternateUrl"></param>
        /// <returns></returns>
        private static string GetAbsoluteUrlByWebAndZone(string url, SPWebApplication web, SPAlternateUrl alternateUrl)
        {
            var site = SPContext.Current.Site;

            // Get current site zone. site.Zone for some reasons always default
            var curZone = GetCurrentZone(site);

            // Get current site url zone or default
            var currentZone = web.AlternateUrls.Where(p => p.UrlZone == curZone).FirstOrDefault();
            if (currentZone == null || string.IsNullOrEmpty(currentZone.Uri.ToString()))
            {
                currentZone = web.AlternateUrls.Where(p => p.UrlZone == SPUrlZone.Default).FirstOrDefault();
            }

            var targetZone = currentZone.Uri.GetUrlString();
            if (alternateUrl != null)
            {
                string currentSiteUrl = alternateUrl.Uri.GetUrlString();
                currentSiteUrl = RemoveEndSlash(currentSiteUrl);
                targetZone = RemoveEndSlash(targetZone);

                var toReturn = url.Replace(currentSiteUrl, targetZone);
                if (toReturn.StartsWith("http"))
                {
                    return toReturn;
                }
                else
                {
                    return CombineUrl(targetZone, toReturn);
                }
            }

            return CombineUrl(targetZone, url);
        }