/// <summary> /// Checks if the WebSiteControllerRules exist /// </summary> /// <returns>true if they exist; otherwise false</returns> public static bool Exists() { if (WebApp == null && HttpContext.Current != null) // && HttpContext.Current.Request != null) { HttpRequest request = HttpContext.Current.Request; string url = HttpContext.Current.Request.Url.OriginalString; //try //{ if (SPSite.Exists(HttpContext.Current.Request.Url)) { SPSite site = new SPSite(HttpContext.Current.Request.Url.OriginalString); WebApp = site.WebApplication; } //} //catch { return false; }; } if (WebApp != null) { if (WebApp != SPAdministrationWebApplication.Local) { WebSiteControllerConfig config = WebApp.GetChild <WebSiteControllerConfig>(OBJECTNAME); return(config != null); } /* * else * { * * return SPFarm.Local.GetObject(ID) != null; * } */ } return(false); /* * try * { * return SPContext.Current.Site.WebApplication.GetChild<WebSiteControllerConfig>(OBJECTNAME) != null; * } * catch (Exception ex) * { * //WebSiteControllerConfig config = SPContext.Current.Site.WebApplication.GetChild<WebSiteControllerConfig>(); * //config.Delete(); * } * return false; */ }
private void CreateWebSiteConfig(SPFeatureReceiverProperties properties) { try { if (webApp != null) { WebSiteControllerConfig config = null; lock (createlock) { config = webApp.GetChild <WebSiteControllerConfig>(WebSiteControllerConfig.OBJECTNAME); if (config == null) { WebSiteControllerConfig settings = new WebSiteControllerConfig(webApp, Guid.NewGuid()); settings.Update(); } } webApp.Update(); } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } }
protected void AddorUpdateConnString() { try { if (ConnectionTest(txtConnString.Text)) { //string sVal = DropDownList1.SelectedItem.Value; //SPWebApplication webApp = SPWebService.ContentService.WebApplications[new Guid(DropDownList1.SelectedValue)]; SPWebApplication webApp = WebApplicationSelector1.CurrentItem; string sError = ""; CoreFunctions.setConnectionString(webApp.Id, txtConnString.Text, out sError); if (sError != "") { lblStatusDyn.Text = "Error: " + sError; lblStatusDyn.BackColor = System.Drawing.Color.Red; } else { lblStatusDyn.Text = "Connection test successful & connection string updated. "; lblStatusDyn.BackColor = System.Drawing.Color.LightGreen; } CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportingServicesURL", txtReportServer.Text); CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsRootFolder", txtDefaultPath.Text); CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsUseIntegrated", chkIntegrated.Checked.ToString()); CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsWindowsAuthentication", chkWindowsAuth.Checked.ToString()); if (txtPassword.Text != "" || txtUsername.Text == "") { ReportAuth _chrono = webApp.GetChild <ReportAuth>("ReportAuth"); if (_chrono == null) { _chrono = new ReportAuth("ReportAuth", webApp, Guid.NewGuid()); _chrono.Update(); //webApp.Update(); } _chrono.Username = txtUsername.Text; _chrono.Password = CoreFunctions.Encrypt(txtPassword.Text, "KgtH(@C*&@Dhflosdf9f#&f"); _chrono.Update(); //webApp.Update(); } } else { lblStatusDyn.Text = "Connection test unsuccessful. Invalid connection string."; lblStatusDyn.BackColor = System.Drawing.Color.Red; } } catch (Exception exception) { lblStatusDyn.Text = "Error: " + exception.Message; lblStatusDyn.BackColor = System.Drawing.Color.Red; } }
/// <summary> /// Removes the setting store. Warning, all settings will be lost when removed. /// </summary> /// <param name="webApp">The web app to clear the settings for</param> public static void DeleteStore(SPWebApplication webApp) { var settingStore = webApp.GetChild <WebAppSettingStore>(WebAppSettingStore.StoreName); if (settingStore != null) { settingStore.Delete(); } }
/// <summary> /// Creates the setting store for a web application /// </summary> /// <param name="webApp">The parent web app to store the settings</param> /// <returns>The web app setting store instance</returns> public static WebAppSettingStore Create(SPWebApplication webApp) { lock (createlock) { //load to make sure it wasn't already created in a race... var settingStore = webApp.GetChild <WebAppSettingStore>(WebAppSettingStore.StoreName); if (settingStore == null) { settingStore = new WebAppSettingStore(WebAppSettingStore.StoreName, webApp); settingStore.Update(); } return(settingStore); } }
protected override void InternalProcessRecord() { SPWebApplication webApp = m_webAppPipeBind.Read(); SignInConfiguration sc = webApp.GetChild <SignInConfiguration>("SignInConfig"); if (sc == null) { sc = new SignInConfiguration("SignInConfig", webApp); } sc.Update(); base.WriteObject(sc); }
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); } } } }
/// <summary> /// Loads the setting store for the farm provided, and creates the setting store if not found. /// </summary> /// <param name="webApp">The farm to use</param> /// <returns>The setting store for farm level settings</returns> public static WebAppSettingStore Load(SPWebApplication webApp) { var settingStore = webApp.GetChild <WebAppSettingStore>(WebAppSettingStore.StoreName); return(settingStore); }
private static void RemoveCleanupTimerJob(SPWebApplication webApplication) { foreach (var job in webApplication.JobDefinitions) { if (job.Name == CleanupLogListTimerJob.JobName) { job.Delete(); break; } } var settings = webApplication.GetChild<CleanupLogListTimerJobSettings>(CleanupLogListTimerJobSettings.SettingsName); if (settings != null) settings.Delete(); ULSLog.LogMessage("Sucessfully removed settings and timer job from Web Application."); }
/// <summary> /// Creates the setting store for a web application /// </summary> /// <param name="webApp">The parent web app to store the settings</param> /// <returns>The web app setting store instance</returns> public static WebAppSettingStore Create(SPWebApplication webApp) { lock (createlock) { //load to make sure it wasn't already created in a race... var settingStore = webApp.GetChild<WebAppSettingStore>(WebAppSettingStore.StoreName); if (settingStore == null) { settingStore = new WebAppSettingStore(WebAppSettingStore.StoreName, webApp); settingStore.Update(); } return settingStore; } }
/// <summary> /// Loads the setting store for the farm provided, and creates the setting store if not found. /// </summary> /// <param name="webApp">The farm to use</param> /// <returns>The setting store for farm level settings</returns> public static WebAppSettingStore Load(SPWebApplication webApp) { var settingStore = webApp.GetChild<WebAppSettingStore>(WebAppSettingStore.StoreName); return settingStore; }
/// <summary> /// Removes the setting store. Warning, all settings will be lost when removed. /// </summary> /// <param name="webApp">The web app to clear the settings for</param> public static void DeleteStore(SPWebApplication webApp) { var settingStore = webApp.GetChild<WebAppSettingStore>(WebAppSettingStore.StoreName); if (settingStore != null) { settingStore.Delete(); } }
protected void GetConnSettings() { try { txtConnString.Text = ""; SPWebApplication webApp = WebApplicationSelector1.CurrentItem; webappid = webApp.Id.ToString(); string sConn = CoreFunctions.getConnectionString(webApp.Id); if (!string.IsNullOrWhiteSpace(sConn)) { txtConnString.Text = sConn; lblStatusDyn.Text = "Active"; SPSecurity.RunWithElevatedPrivileges(delegate() { try { var curVersion = ""; using (var cn = new SqlConnection(sConn)) { cn.Open(); using (var cmd = new SqlCommand("SELECT TOP 1 VERSION FROM VERSIONS order by dtInstalled DESC", cn)) { using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { curVersion = dr.GetString(0); } } } } lblVersion.Text = curVersion; if (curVersion != CoreFunctions.GetFullAssemblyVersion()) { btnUpgrade.Visible = true; lblVersion.BackColor = Color.Red; } } catch (Exception ex) { lblStatusDyn.Text = "Error: " + ex.Message; } }); } else { lblStatusDyn.Text = "No connection string configured."; con1.Visible = false; con3.Visible = false; btnInstallDB.Visible = true; } ReportAuth _chrono = webApp.GetChild <ReportAuth>("ReportAuth"); if (_chrono != null) { txtUsername.Text = _chrono.Username; } if (SPFarm.Local.Solutions[new Guid("55aca119-d7c7-494a-b5a7-c3ade07d06eb")].DeployedWebApplications.Contains(webApp)) { sCoreStatus = "Deployed"; } else { sCoreStatus = "Not Deployed"; } if (SPFarm.Local.Solutions[new Guid("98e5c373-e1a0-45ce-8124-30c203cd8003")].DeployedWebApplications.Contains(webApp)) { sWPStatus = "Deployed"; } else { sWPStatus = "Not Deployed"; } if (SPFarm.Local.Solutions[new Guid("1858d521-0375-4a61-9281-f5210854bc12")].DeployedWebApplications.Contains(webApp)) { sTSStatus = "Deployed"; } else { sTSStatus = "Not Deployed"; } if (SPFarm.Local.Solutions[new Guid("8f916fa9-1c2d-4416-8036-4a272256e23d")].DeployedWebApplications.Contains(webApp)) { sDashboardStatus = "Deployed"; } else { sDashboardStatus = "Not Deployed"; } if (SPFarm.Local.Solutions[new Guid("5a3fe24c-2dc5-4a1c-aec1-6ce942825ceb")].DeployedWebApplications.Contains(webApp)) { sPFEStatus = "Deployed"; } else { sPFEStatus = "Not Deployed"; } } catch (Exception exception) { lblStatusDyn.Text = "Error: " + exception.Message; lblStatusDyn.BackColor = System.Drawing.Color.Red; } try { txtReportServer.Text = CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportingServicesURL"); txtDefaultPath.Text = CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsRootFolder"); chkIntegrated.Checked = bool.Parse(CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsUseIntegrated")); chkWindowsAuth.Checked = bool.Parse(CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsWindowsAuthentication")); } catch { } }