Ejemplo n.º 1
0
        /// <summary>
        /// Extends the web app.
        /// </summary>
        /// <param name="webApplication">The web application.</param>
        /// <param name="description">The description.</param>
        /// <param name="hostHeader">The host header.</param>
        /// <param name="port">The port.</param>
        /// <param name="loadBalancedUrl">The load balanced URL.</param>
        /// <param name="path">The path.</param>
        /// <param name="allowAnonymous">if set to <c>true</c> [allow anonymous].</param>
        /// <param name="useNtlm">if set to <c>true</c> [use NTLM].</param>
        /// <param name="useSsl">if set to <c>true</c> [use SSL].</param>
        /// <param name="zone">The zone.</param>
        public static void ExtendWebApp(SPWebApplication webApplication, string description, string hostHeader, int port, string loadBalancedUrl, string path, bool allowAnonymous, bool useNtlm, bool useSsl, SPUrlZone zone)
        {
            SPServerBinding serverBinding = null;
            SPSecureBinding secureBinding = null;

            if (!useSsl)
            {
                serverBinding            = new SPServerBinding();
                serverBinding.Port       = port;
                serverBinding.HostHeader = hostHeader;
            }
            else
            {
                secureBinding      = new SPSecureBinding();
                secureBinding.Port = port;
            }

            SPIisSettings settings = new SPIisSettings(description, allowAnonymous, useNtlm, serverBinding, secureBinding, new DirectoryInfo(path.Trim()));

            settings.PreferredInstanceId = GetPreferredInstanceId(description);

            webApplication.IisSettings.Add(zone, settings);
            webApplication.AlternateUrls.SetResponseUrl(new SPAlternateUrl(new Uri(loadBalancedUrl), zone));
            webApplication.AlternateUrls.Update();
            webApplication.Update();
            webApplication.ProvisionGlobally();
        }
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues,
                                    out string output)
        {
            output = string.Empty;

            Uri uri = new Uri(Params["url"].Value);

            SPWebApplicationBuilder builder = GetWebAppBuilder(uri);

            SPWebApplication app = builder.Create();

            SPAdministrationWebApplication local = SPAdministrationWebApplication.Local;

            // Set the TimeZone of the Application
            if (Params["timezone"].UserTypedIn)
            {
                app.DefaultTimeZone = ushort.Parse(Params["timezone"].Value);
            }

            app.Update();
            app.ProvisionGlobally();

            // Execute pending timer jobs before moving on.
            Common.TimerJobs.ExecAdmSvcJobs.Execute(false, true);
            // Recreate the web application object to avoid update conflicts.
            app = SPWebApplication.Lookup(uri);

            // Upload the newly created WebApplication to the List 'Web Application List' in Central Administration:
            SPWebService.AdministrationService.WebApplications.Add(app);

            if (!Params["donotcreatesite"].UserTypedIn)
            {
                uint   nLCID       = uint.Parse(Params["lcid"].Value);
                string webTemplate = Params["sitetemplate"].Value;
                string ownerLogin  = Params["ownerlogin"].Value;
                ownerLogin = Utilities.TryGetNT4StyleAccountName(ownerLogin, app);
                string ownerName  = Params["ownername"].Value;
                string ownerEmail = Params["owneremail"].Value;

                app.Sites.Add(uri.AbsolutePath, null, null, nLCID, webTemplate, ownerLogin, ownerName, ownerEmail, null, null, null);
            }


            Console.WriteLine(SPResource.GetString("PendingRestartInExtendWebFarm", new object[0]));
            Console.WriteLine();

            if (!Params["donotcreatesite"].UserTypedIn)
            {
                Console.WriteLine(SPResource.GetString("AccessSiteAt", new object[] { uri.ToString() }));
            }
            Console.WriteLine();

            return((int)ErrorCodes.NoError);
        }
        protected void RemoveFbaSettings(SPWebApplication webApp, SPFeatureReceiverProperties properties)
        {
            using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    try
                    {
                        SPList list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings");

                        if (list != null)
                        {
                            SPListItemCollection items = list.Items;

                            foreach (SPListItem item in items)
                            {
                                var zone = GetZone(item);

                                if (item["WebApplicationUrl"].ToString() == webApp.GetResponseUri(zone).AbsoluteUri)
                                {
                                    //Remove the Forms Authentication provider for the Web Application
                                    try
                                    {
                                        foreach (var provider in
                                                 webApp.IisSettings[zone].ClaimsAuthenticationProviders)
                                        {
                                            if (provider.ClaimProviderName == "Forms")
                                            {
                                                webApp.IisSettings[zone].DeleteClaimsAuthenticationProvider(provider);
                                                webApp.Update();
                                                webApp.ProvisionGlobally();
                                                break;
                                            }
                                        }
                                    }
                                    catch (ArgumentNullException)
                                    {
                                        //Forms provider already removed
                                    }
                                    catch (ArgumentException)
                                    {
                                        //Claims provider is null
                                    }
                                    finally
                                    {
                                        webApp.IisSettings[zone].ClaimsAuthenticationRedirectionUrl = null;
                                        webApp.Update();
                                        webApp.ProvisionGlobally();
                                    }

                                    WebModifications.CreateWildcardNode(true, webApp, zone);
                                    WebModifications.CreateProviderNode(true, webApp, zone);
                                    WebModifications.CreateStsProviderNode(true, properties, zone);
                                    WebModifications.CreateAdminWildcardNode(true, webApp, zone);
                                    WebModifications.CreateAdminProviderNode(true, webApp, zone);

                                    var local = SPFarm.Local;

                                    var services = from s in local.Services
                                                   where s.Name == "SPTimerV4"
                                                   select s;

                                    var service = services.First();

                                    foreach (var job in service.JobDefinitions)
                                    {
                                        if (job.Name == tJobName)
                                        {
                                            if (job.IsDisabled)
                                            {
                                                job.IsDisabled = false;
                                            }
                                            job.Update();
                                            job.RunNow();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (SPException ex)
                    {
                        Logging.LogMessage(951, Logging.LogCategories.STSXML, TraceSeverity.Unexpected,
                                           String.Format("Unable to update the WebApplicationSettings List in Central Administration. {0}",
                                                         ex.StackTrace),
                                           new object[] { null });
                        throw new SPException(@"Unable to update the WebApplicationSettings List in Central Administration.  Validate the list exists.");
                    }
                }
            }
        }
        /// <summary>
        /// Extends the web app.
        /// </summary>
        /// <param name="webApplication">The web application.</param>
        /// <param name="description">The description.</param>
        /// <param name="hostHeader">The host header.</param>
        /// <param name="port">The port.</param>
        /// <param name="loadBalancedUrl">The load balanced URL.</param>
        /// <param name="path">The path.</param>
        /// <param name="allowAnonymous">if set to <c>true</c> [allow anonymous].</param>
        /// <param name="useNtlm">if set to <c>true</c> [use NTLM].</param>
        /// <param name="useSsl">if set to <c>true</c> [use SSL].</param>
        /// <param name="zone">The zone.</param>
        public static void ExtendWebApp(SPWebApplication webApplication, string description, string hostHeader, int port, string loadBalancedUrl, string path, bool allowAnonymous, bool useNtlm, bool useSsl, SPUrlZone zone)
        {
            SPServerBinding serverBinding = null;
            SPSecureBinding secureBinding = null;
            if (!useSsl)
            {
                serverBinding = new SPServerBinding();
                serverBinding.Port = port;
                serverBinding.HostHeader = hostHeader;
            }
            else
            {
                secureBinding = new SPSecureBinding();
                secureBinding.Port = port;
            }

            SPIisSettings settings = new SPIisSettings(description, allowAnonymous, useNtlm, serverBinding, secureBinding, new DirectoryInfo(path.Trim()));
            settings.PreferredInstanceId = GetPreferredInstanceId(description);

            webApplication.IisSettings.Add(zone, settings);
            webApplication.AlternateUrls.SetResponseUrl(new SPAlternateUrl(new Uri(loadBalancedUrl), zone));
            webApplication.AlternateUrls.Update();
            webApplication.Update();
            webApplication.ProvisionGlobally();
        }