static ALEXFWAuthentication() { _Config = WebConfigurationManager.OpenWebConfiguration("~"); SystemWebSectionGroup system = (SystemWebSectionGroup)_Config.GetSectionGroup("system.web"); IsEnabled = system.Authentication.Mode == AuthenticationMode.Forms; if (!IsEnabled) { return; } if (!_Config.AppSettings.Settings.AllKeys.Contains("ALEXFWAuthenticationKey")) { _Key = Guid.NewGuid().ToByteArray(); _Config.AppSettings.Settings.Add("ALEXFWAuthenticationKey", Convert.ToBase64String(_Key)); _Config.Save(); } else { _Key = Convert.FromBase64String(_Config.AppSettings.Settings["ALEXFWAuthenticationKey"].Value); } CookieDomain = system.Authentication.Forms.Domain; CookieName = system.Authentication.Forms.Name ?? "ALEXFWauth"; CookiePath = system.Authentication.Forms.Path; LoginUrl = system.Authentication.Forms.LoginUrl; Timeout = system.Authentication.Forms.Timeout; }
private static bool Debug() { Configuration configuration = WebConfigurationManager.OpenWebConfiguration(""); SystemWebSectionGroup ws = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); CompilationSection cp = ws.Compilation; return(cp.Debug); }
private IRoleManager LoadAndInitializeRoleProvider(SystemWebSectionGroup remoteWebConfigurationGroup) { var roleSection = remoteWebConfigurationGroup.RoleManager; var providerSettings = roleSection.Providers[remoteWebConfigurationGroup.RoleManager.DefaultProvider]; var roleProvider = providerFactory.CreateProviderFromConfig <RoleProvider>(providerSettings); return(new RoleManager(roleProvider, roleSection)); }
public ContentNotModifiedFilter(HttpResponseBase response, HttpRequestBase request) { SystemWebSectionGroup config = (SystemWebSectionGroup)WebConfigurationManager.OpenWebConfiguration("~/Web.Config").SectionGroups["system.web"]; CompilationSection cp = config.Compilation; m_Debug = cp.Debug; m_Response = response; m_Request = request; m_Filter = response.Filter; }
public ActionResult Index() { Dictionary <string, string> configData = new Dictionary <string, string>(); SystemWebSectionGroup sysWeb = (SystemWebSectionGroup)WebConfigurationManager.OpenWebConfiguration("/") .GetSectionGroup("system.web"); configData.Add("debug", sysWeb.Compilation.Debug.ToString()); configData.Add("targetFramework", sysWeb.Compilation.TargetFramework); return(View(configData)); }
public void Init(HttpApplication context) { // 捕获全局未处理的异常 context.Error += new EventHandler(context_Error); context.PreSendRequestHeaders += new EventHandler(PreSendRequestHeadersHandler); Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/"); SystemWebSectionGroup ws = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); loginUrl = ws.Authentication.Forms.LoginUrl.ToLower(); }
public ContentNotModifiedFilter(HttpContextBase httpContext, int serverCacheExpiredMinutes, bool hasCacheItem) { SystemWebSectionGroup config = (SystemWebSectionGroup)WebConfigurationManager.OpenWebConfiguration("~/Web.Config").SectionGroups["system.web"]; CompilationSection cp = config.Compilation; m_Debug = cp.Debug; m_HttpContext = httpContext; m_Response = httpContext.Response; m_Request = httpContext.Request; m_Filter = m_Response.Filter; m_ServerCacheExpiredMinutes = serverCacheExpiredMinutes; m_HasCacheItem = hasCacheItem; }
private IMembershipManager LoadAndInitializeMembershipProvider(SystemWebSectionGroup remoteWebConfigurationGroup) { var membershipSection = remoteWebConfigurationGroup.Membership; var providerSettings = membershipSection.Providers[remoteWebConfigurationGroup.Membership.DefaultProvider]; var membershipProvider = providerFactory.CreateProviderFromConfig <MembershipProvider>(providerSettings); RemoveReadonlyFlagFromProviderCollection(Membership.Providers); Membership.Providers.Clear(); Membership.Providers.Add(membershipProvider); return(new MembershipManager(membershipProvider)); }
public ActionResult AddTimeout(int sessiontime) { bool flag = false; SessionDataAccess sda = new SessionDataAccess(); flag = sda.InsertSessionTimeout(sessiontime); Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); SystemWebSectionGroup syswebSection = (SystemWebSectionGroup)config.GetSectionGroup("system.web"); //you can change the value as you want syswebSection.SessionState.Timeout = new TimeSpan(0, sessiontime, 0); config.Save(); return(Json(new { result = flag, ErrorMessage = CustomMessages.Success }, JsonRequestBehavior.AllowGet)); }
private static void RegisterViewRequestHandler() { System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration( HttpContext.Current.Request.ApplicationPath); SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); try { systemWeb.HttpModules.Modules.Add(new HttpModuleAction("WebformsViewRequestHandler", typeof(WebformsViewRequestHandler).FullName)); configuration.Save(); } catch (ConfigurationErrorsException) { } }
public static void SetValue(string key, string value) { Configuration config = WebConfigurationManager.OpenWebConfiguration("~/xml/"); //ConnectionStringSettings test = new ConnectionStringSettings("test1", "test1", "test1.dll"); //config.ConnectionStrings.ConnectionStrings.Add(test); //<add src="~/WebPart/ProductCate.ascx" tagName="cate" tagPrefix="uc" /> TagPrefixInfo dd = new TagPrefixInfo("uc", "", "", "cate", "~/WebPart/ProductCate.ascx"); //config.SectionGroups["system.web"] SystemWebSectionGroup t = new SystemWebSectionGroup(); t.Pages.Controls.Add(dd); config.Save(ConfigurationSaveMode.Modified); }
public void MoveRule(object sender, EventArgs e, string upOrDown) { /* * Dan Clem, 3/17/2007 */ upOrDown = upOrDown.ToLower(); if (upOrDown == "up" || upOrDown == "down") { Button button = (Button)sender; GridViewRow item = (GridViewRow)button.Parent.Parent; int selectedIndex = item.RowIndex; if ((selectedIndex > 0 && upOrDown == "up") || (upOrDown == "down")) { string virtualFolderPath = FolderTree.SelectedValue; Configuration config = WebConfigurationManager.OpenWebConfiguration(virtualFolderPath); SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)config.GetSectionGroup("system.web"); AuthorizationSection section = (AuthorizationSection)systemWeb.Sections["authorization"]; // Pull the local rules out of the authorization section, deleting them from same: ArrayList rulesArray = PullLocalRulesOutOfAuthorizationSection(section); if (upOrDown == "up") { LoadRulesInNewOrder(section, rulesArray, selectedIndex, upOrDown); } else if (upOrDown == "down") { if (selectedIndex < rulesArray.Count - 1) { LoadRulesInNewOrder(section, rulesArray, selectedIndex, upOrDown); } else { // DOWN button in last row was pressed. Load the rules array back in without resorting. for (int x = 0; x < rulesArray.Count; x++) { section.Rules.Add((AuthorizationRule)rulesArray[x]); } } } config.Save(); } } }
public void AddRule(AuthorizationRule newRule) { string virtualFolderPath = FolderTree.SelectedValue; Configuration config = WebConfigurationManager.OpenWebConfiguration(virtualFolderPath); SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)config.GetSectionGroup("system.web"); AuthorizationSection section = (AuthorizationSection)systemWeb.Sections["authorization"]; section.Rules.Add(newRule); try { config.Save(); RuleCreationError.Visible = false; } catch (Exception ex) { RuleCreationError.Visible = true; RuleCreationError.Text = "<div class=\"alert\"><br />An error occurred and the rule was not added. I saw this happen during testing when I attempted to create a rule that the ASP.NET infrastructure realized was redundant. Specifically, I had the rule <i>DENY ALL USERS</i> in one folder, then attempted to add the same rule in a subfolder, which caused ASP.NET to throw an exception.<br /><br />Here's the error message that was thrown just now:<br /><br /><i>" + ex.Message + "</i></div>"; } }
public static void InitWebConfig(System.Configuration.Configuration conf, bool useAcessProviders, string connectionStringName) { SystemWebSectionGroup websec = conf.GetSectionGroup("system.web") as SystemWebSectionGroup; websec.Authentication.Mode = AuthenticationMode.Forms; //if (useAcessProviders) //{ // AccessMembershipProvider.SetPrividerSettings(websec.Membership, connectionStringName); // AccessRoleProvider.SetRoleSettings(websec.RoleManager, connectionStringName); //} //else //{ UniMembershipProvider.SetPrividerSettings(websec.Membership, connectionStringName); MyRoleManager.SetRoleSettings(websec.RoleManager, connectionStringName); //} CreateHttpHandler(websec); InitConfigSections(ref conf); InitJcoSecuritySection(conf); conf.Save(); }
private IProfileManager LoadAndInitializeProfileProvider(SystemWebSectionGroup remoteWebConfigurationGroup) { var profileConfiguration = remoteWebConfigurationGroup.Profile; if (profileConfiguration.Enabled) { if (profileConfiguration.Inherits.IsNotNullOrEmpty() && Type.GetType(profileConfiguration.Inherits) == null) { var profileTypeAssembly = GetAssemblyForProfileType(profileConfiguration); AppDomain.CurrentDomain.AssemblyResolve += (obj, args) => { if (args.Name == profileTypeAssembly.FullName) { return(profileTypeAssembly); } return(null); }; AppDomain.CurrentDomain.TypeResolve += (obj, args) => { if (args.Name.StartsWith(profileConfiguration.Inherits)) { return(profileTypeAssembly); } return(null); }; } var defaultProfileProviderConfiguration = remoteWebConfigurationGroup.Profile.Providers[remoteWebConfigurationGroup.Profile.DefaultProvider]; var profileProvider = providerFactory.CreateProviderFromConfig <ProfileProvider>(defaultProfileProviderConfiguration); RemoveReadonlyFlagFromProviderCollection(System.Web.Profile.ProfileManager.Providers); System.Web.Profile.ProfileManager.Providers.Clear(); System.Web.Profile.ProfileManager.Providers.Add(profileProvider); } return(new ProfileManager(profileConfiguration)); }
public void DisplayAccessRules(string virtualFolderPath) { if (!virtualFolderPath.StartsWith(VirtualImageRoot) || virtualFolderPath.IndexOf("..") >= 0) { /* * Dan Clem, 3/15/2007: from my brief testing, it appears that this may not be necessary, since ASP.NET seems to prevent this inherently, throwing this error: * Cannot use a leading .. to exit above the top directory. * I'm keeping it anyway, 'cause that's how 4guys did it. */ throw new ApplicationException("An attempt to access a folder outside of the website directory has been detected and blocked."); } Configuration config = WebConfigurationManager.OpenWebConfiguration(virtualFolderPath); SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)config.GetSectionGroup("system.web"); AuthorizationRuleCollection authorizationRules = systemWeb.Authorization.Rules; RulesGrid.DataSource = authorizationRules; RulesGrid.DataBind(); TitleOne.InnerText = "Rules applied to " + virtualFolderPath; TitleTwo.InnerText = "Create new rule for " + virtualFolderPath; }
public static void InitializeSql(string connectionStringName) { if (initialized) { return; } try { System.Configuration.Configuration conf = ConfigUtility.GetConfigFile(); SystemWebSectionGroup websec = conf.GetSectionGroup("system.web") as SystemWebSectionGroup; WebConfigInitializer.InitWebConfig(conf, false, connectionStringName); } catch { } if (!DatabaseTablesExist) { InitSqlDatabase(connectionStringName); } initialized = true; }
public void DeleteRule(object sender, EventArgs e) { /* * Dan Clem, 3/16/2007. * This is working quite well, however there is a defect that I am not planning to fix right now. * If you delete a rule, then attempt to delete another rule from the same folder without * refreshing the page, you'll get a page error. The workaround is to re-click the folder in the * tree to refresh it, then delete the rule. * Don't feel like worrying about this right now. * * Note: this problem may have been fixed already. * I stopped using the session array method for handling things. * This may have fixed it. I'll test later. */ Button button = (Button)sender; GridViewRow item = (GridViewRow)button.Parent.Parent; string virtualFolderPath = FolderTree.SelectedValue; Configuration config = WebConfigurationManager.OpenWebConfiguration(virtualFolderPath); SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)config.GetSectionGroup("system.web"); AuthorizationSection section = (AuthorizationSection)systemWeb.Sections["authorization"]; section.Rules.RemoveAt(item.RowIndex); config.Save(); }
private void CreateDatabaseConnectionStringsForProviders(ConnectionStringsSection connectionStringsSection, SystemWebSectionGroup webSectionGroup) { var connectionStringNames = GetDatabaseConnectionStringsForProvider(webSectionGroup.RoleManager.Providers) .Union(GetDatabaseConnectionStringsForProvider(webSectionGroup.Membership.Providers)) .Union(GetDatabaseConnectionStringsForProvider(webSectionGroup.Profile.Providers)) .Distinct() .Intersect(connectionStringsSection.ConnectionStrings.Cast <ConnectionStringSettings>().Select(x => x.Name)); var connectionStrings = connectionStringNames.Select(connectionStringName => connectionStringsSection.ConnectionStrings[connectionStringName].ConnectionString); foreach (var connectionString in connectionStrings) { var connection = new SqlConnectionStringBuilder(connectionString); var database = connection.InitialCatalog; connection.InitialCatalog = string.Empty; SqlServices.Install(database, SqlFeatures.All, connection.ConnectionString); } }
internal static bool CheckConfig(Control control) { if (initialized) { return(true); } string error; HyperLink lnk = new HyperLink(); if (CheckAppConfiguration(out error)) { //if (Array.IndexOf<string>(Roles.GetAllRoles(), "admin") == -1 && Array.IndexOf<string>(Roles.GetAllRoles(), "Admin") == -1) if (Roles.GetAllRoles().Length == 0) { Roles.CreateRole("admin"); } if ((Membership.GetUser("admin") == null || Membership.GetUser("Admin") == null) && Membership.GetAllUsers().Count == 0) { lnk.Text = "<br>کاربر Admin ايجاد نشده است<br/>براي ايجاد کاربر اينجا را کليک کنيد."; lnk.NavigateUrl = UniHttpHandler.HandlerPath + "?a=conf&b=" + HttpContext.Current.Request.Path + "&p=2"; lnk.ToolTip = "کاربر Admin وجود ندارد"; control.Controls.Add(lnk); } else { initialized = true; } return(true); } System.Configuration.Configuration conf = null; try { conf = ConfigUtility.GetConfigFile(); } catch (Exception ex) { error = ex.ToString(); } if (conf != null) { try { foreach (ConfigurationLocation location in conf.Locations) { if (location.Path == UniHttpHandler.HandlerPath) { System.Configuration.Configuration lconf = location.OpenConfiguration(); SystemWebSectionGroup lweb = ConfigUtility.GetSystemWebSectionGroup(lconf); lweb.Authorization.Rules.Clear(); AuthorizationRule rule = new AuthorizationRule(AuthorizationRuleAction.Allow); rule.Users.Add("*"); lweb.Authorization.Rules.Add(rule); lconf.Save(); } } //WebConfigInitializer.CreateHttpHandler(ConfigUtility.GetSystemWebSectionGroup(conf)); conf.Save(); } catch (Exception ex) { error = ex.ToString(); } } //LinkButton btn = new LinkButton(); //btn.Text = "تنظيمات امنيتي سايت اتجام نشده است<br/>براي انجام تنظيمات اينجا را کليک کنيد."; //btn.Click += new EventHandler( btnDoConfig_Click ); //btn.CausesValidation = false; //btn.ID = "JcoSecDoConfigButton"; //control.Controls.Add( btn ); //control.Page.PreRender += new EventHandler( Page_PreRender ); //initAddedButtons.Add( btn ); lnk.Text = "تنظيمات امنيتي سايت اتجام نشده است<br/>براي انجام تنظيمات اينجا را کليک کنيد."; lnk.NavigateUrl = UniHttpHandler.HandlerPath + "?a=conf&b=" + HttpContext.Current.Request.Path; lnk.ToolTip = error; control.Controls.Add(lnk); return(false); }
//static void btnDoConfig_Click(object sender, EventArgs e) //{ // Initialize(); //} public static bool CheckAppConfiguration(out string error) { //error=""; //return true; try { error = ""; System.Configuration.Configuration conf = null; try { conf = ConfigUtility.GetConfigFile(); } catch { } SystemWebSectionGroup websec = ConfigUtility.GetSystemWebSectionGroup(conf); if (websec.Authentication.Mode != AuthenticationMode.Forms) { error = "Authentication.Mode = " + websec.Authentication.Mode.ToString(); } if (websec.Membership.DefaultProvider != UniMembershipProvider.ProviderName) { //&& websec.Membership.DefaultProvider != AccessMembershipProvider.ProviderName) if (websec.Membership.DefaultProvider == null) { error = "Membership.DefaultProvider = null"; } else { error = "Membership.DefaultProvider = " + websec.Membership.DefaultProvider; } } if (!Roles.Enabled) { error = "Roles is not enabled."; } if (error != "") { return(false); } //UniSecuritySectionGroup jcoSec = (UniSecuritySectionGroup)conf.GetSectionGroup("uniSecurity"); //if (jcoSec == null) // error = "UniSecuritySectionGroup is not defined."; //if (jcoSec.MasterPage.Path == "") // error = "JcoSecuritySectionGroup.MasterPage.Path is empty."; if (error != "") { return(false); } if (websec.Membership.DefaultProvider == UniMembershipProvider.ProviderName) { string conName = websec.Membership.Providers[UniMembershipProvider.ProviderName].Parameters["connectionStringName"]; bool b = CheckSqlTablesExists(conf.ConnectionStrings.ConnectionStrings[conName].ConnectionString); if (!b) { error = "Sql tables doen not exists."; return(false); } } else { throw new NotSupportedException(); //string conName = websec.Membership.Providers[AccessMembershipProvider.ProviderName].Parameters["connectionStringName"]; //if (!File.Exists(HttpContext.Current.Server.MapPath(conf.ConnectionStrings.ConnectionStrings[conName].ConnectionString))) //{ // error = "Access DB file: '" + conf.ConnectionStrings.ConnectionStrings[conName].ConnectionString + "' does not exists."; // return false; //} } } catch (Exception ex) { error = ex.ToString(); return(false); } return(true); }
static void Main(string[] args) { string inputStr = String.Empty; string option = String.Empty; // Define a regular expression to allow only // alphanumeric inputs that are at most 20 character // long. For instance "/iii:". Regex rex = new Regex(@"[^\/w]{1,20}:"); // Parse the user's input. if (args.Length < 1) { // No option entered. Console.Write("Input parameter missing."); return; } else { // Get the user's option. inputStr = args[0].ToLower(); if (!(rex.Match(inputStr)).Success) { // Wrong option format used. Console.Write("Input parameter format not allowed."); return; } } // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration( "/aspnetTest"); // Get the <system.web> group. SystemWebSectionGroup systemWeb = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web"); // </Snippet1> try { switch (inputStr) { case "/anonymous:": // <Snippet2> // Get the anonymousIdentification section. AnonymousIdentificationSection anonymousIdentification = systemWeb.AnonymousIdentification; // Read section information. info = anonymousIdentification.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet2> Console.Write(msg); break; case "/authentication:": // <Snippet3> // Get the authentication section. AuthenticationSection authentication = systemWeb.Authentication; // Read section information. info = authentication.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet3> Console.Write(msg); break; case "/authorization:": // <Snippet4> // Get the authorization section. AuthorizationSection authorization = systemWeb.Authorization; // Read section information. info = authorization.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet4> Console.Write(msg); break; case "/compilation:": // <Snippet5> // Get the compilation section. CompilationSection compilation = systemWeb.Compilation; // Read section information. info = compilation.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet5> Console.Write(msg); break; case "/customerrors:": // <Snippet6> // Get the customerrors section. CustomErrorsSection customerrors = systemWeb.CustomErrors; // Read section information. info = customerrors.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet6> Console.Write(msg); break; case "/globalization:": // <Snippet7> // Get the globalization section. GlobalizationSection globalization = systemWeb.Globalization; // Read section information. info = globalization.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet7> Console.Write(msg); break; case "/httpcookies:": // <Snippet8> // Get the httpCookies section. HttpCookiesSection httpCookies = systemWeb.HttpCookies; // Read section information. info = httpCookies.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet8> Console.Write(msg); break; case "/httphandlers:": // <Snippet9> // Get the httpHandlers section. HttpHandlersSection httpHandlers = systemWeb.HttpHandlers; // Read section information. info = httpHandlers.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet9> Console.Write(msg); break; case "/httpmodules:": // <Snippet10> // Get the httpModules section. HttpModulesSection httpModules = systemWeb.HttpModules; // Read section information. info = httpModules.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet10> Console.Write(msg); break; case "/httpruntime:": // <Snippet11> // Get the httpRuntime section. HttpRuntimeSection httpRuntime = systemWeb.HttpRuntime; // Read section information. info = httpRuntime.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet11> Console.Write(msg); break; case "/identity:": // <Snippet12> // Get the identity section. IdentitySection identity = systemWeb.Identity; // Read section information. info = identity.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet12> Console.Write(msg); break; case "/machinekey:": // <Snippet13> // Get the machineKey section. MachineKeySection machineKey = systemWeb.MachineKey; // Read section information. info = machineKey.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet13> Console.Write(msg); break; case "/membership:": // <Snippet14> // Get the membership section. MembershipSection membership = systemWeb.Membership; // Read section information. info = membership.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet14> Console.Write(msg); break; case "/pages:": // <Snippet15> // Get the pages section. PagesSection pages = systemWeb.Pages; // Read section information. info = pages.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet15> Console.Write(msg); break; case "/processModel:": // <Snippet16> // Get the processModel section. ProcessModelSection processModel = systemWeb.ProcessModel; // Read section information. info = processModel.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet16> Console.Write(msg); break; case "/profile:": // <Snippet17> // Get the profile section. ProfileSection profile = systemWeb.Profile; // Read section information. info = profile.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet17> Console.Write(msg); break; case "/roleManager:": // <Snippet18> // Get the roleManager section. RoleManagerSection roleManager = systemWeb.RoleManager; // Read section information. info = roleManager.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet18> Console.Write(msg); break; case "/securityPolicy:": // <Snippet19> // Get the securityPolicy section. SecurityPolicySection securityPolicy = systemWeb.SecurityPolicy; // Read section information. info = securityPolicy.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet19> Console.Write(msg); break; case "/sessionState:": // <Snippet20> // Get the sessionState section. SessionStateSection sessionState = systemWeb.SessionState; // Read section information. info = sessionState.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet20> Console.Write(msg); break; case "/sitemap:": // <Snippet21> // Get the siteMap section. SiteMapSection siteMap = systemWeb.SiteMap; // Read section information. info = siteMap.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet21> Console.Write(msg); break; case "/trace:": // <Snippet22> // Get the trace section. TraceSection trace = systemWeb.Trace; // Read section information. info = trace.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet22> Console.Write(msg); break; case "/trust:": // <Snippet23> // Get the trust section. TrustSection trust = systemWeb.Trust; // Read section information. info = trust.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet23> Console.Write(msg); break; case "/browserCaps:": // <Snippet24> // Get the browserCaps section. DefaultSection browserCaps = systemWeb.BrowserCaps; // Read section information. info = browserCaps.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet24> Console.Write(msg); break; case "/clientTarget:": // <Snippet25> // Get the clientTarget section. ClientTargetSection clientTarget = systemWeb.ClientTarget; // Read section information. info = clientTarget.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet25> Console.Write(msg); break; case "/deployment:": // <Snippet26> // Get the deployment section. DeploymentSection deployment = systemWeb.Deployment; // Read section information. info = deployment.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet26> Console.Write(msg); break; case "/deviceFilters:": // <Snippet27> // Get the deviceFilters section. DefaultSection deviceFilters = systemWeb.DeviceFilters; // Read section information. info = deviceFilters.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet27> Console.Write(msg); break; case "/healthMonitoring:": // <Snippet28> // Get the healthMonitoring section. HealthMonitoringSection healthMonitoring = systemWeb.HealthMonitoring; // Read section information. info = healthMonitoring.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet28> Console.Write(msg); break; case "/hostingEnvironment:": // <Snippet29> // Get the hostingEnvironment section. HostingEnvironmentSection hostingEnvironment = systemWeb.HostingEnvironment; // Read section information. info = hostingEnvironment.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet29> Console.Write(msg); break; case "/mobileControls:": // <Snippet30> // Get the mobileControls section. ConfigurationSection mobileControls = systemWeb.MobileControls; // Read section information. info = mobileControls.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet30> Console.Write(msg); break; case "/protocols:": // <Snippet31> // Get the protocols section. DefaultSection protocols = systemWeb.Protocols; // Read section information. info = protocols.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet31> Console.Write(msg); break; case "/urlMappings:": // <Snippet32> // Get the urlMappings section. UrlMappingsSection urlMappings = systemWeb.UrlMappings; // Read section information. info = urlMappings.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet32> Console.Write(msg); break; case "/webControls:": // <Snippet33> // Get the webControls section. WebControlsSection webControls = systemWeb.WebControls; // Read section information. info = webControls.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet33> Console.Write(msg); break; case "/webParts:": // <Snippet34> // Get the webParts section. WebPartsSection webParts = systemWeb.WebParts; // Read section information. info = webParts.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet34> Console.Write(msg); break; case "/webServices:": // <Snippet35> // Get the webServices section. WebServicesSection webServices = systemWeb.WebServices; // Read section information. info = webServices.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet35> Console.Write(msg); break; case "/XhtmlConformance:": // <Snippet36> // Get the xhtmlConformance section. XhtmlConformanceSection xhtmlConformance = systemWeb.XhtmlConformance; // Read section information. info = xhtmlConformance.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); msg = String.Format( "Name: {0}\nDeclared: {1}\nType: {2}\n", name, declared, type); // </Snippet36> Console.Write(msg); break; case "/all:": StringBuilder allSections = new StringBuilder(); ConfigurationSectionGroup systemWebGroup = configuration.GetSectionGroup("system.web"); int i = 0; foreach (ConfigurationSection section in systemWebGroup.Sections) { i += 1; info = section.SectionInformation; name = info.SectionName; type = info.Type; declared = info.IsDeclared.ToString(); if (i < 10) { msg = String.Format( "{0})Name: {1}\nDeclared: {2}\nType: {3}\n", i.ToString(), name, declared, type); } else { msg = String.Format( "{0})Name: {1}\nDeclared: {2}\nType: {3}\n", i.ToString(), name, declared, type); } allSections.AppendLine(msg); } // Console.WriteLine(systemWebGroup.Name); // Console.WriteLine(systemWebGroup.SectionGroupName); Console.Write(allSections.ToString()); break; default: // Option is not allowed.. Console.Write("Input not allowed."); break; } } catch (ArgumentException e) { // Never display this. Use it for // debugging purposes. msg = e.ToString(); } }
public override void Add(IList <EndpointConfig> endpointConfigs) { ThrowIfClosed(); Configuration config = GetConfiguration(false); // not read only Debug.Assert(config != null, "config != null"); bool anyAdded = false; const string systemWebSection = "system.web"; foreach (EndpointConfig endpointConfig in endpointConfigs) { Guid appid; //verify that we someone did not delete and reinstall the app from underneath us if (this.svcFileManager.ResolveClsid(endpointConfig.Clsid, out appid)) { if (endpointConfig.Appid != appid) { ToolConsole.WriteError(SR.GetString(SR.AppIDsDontMatch), ""); return; } } } SystemWebSectionGroup swsg = (SystemWebSectionGroup)config.GetSectionGroup(systemWebSection); CompilationSection compilationSection = swsg.Compilation; if (string.IsNullOrEmpty(compilationSection.TargetFramework) && RuntimeVersions.V40 == this.runtimeVersion) { anyAdded = true; compilationSection.TargetFramework = ".NETFramework, Version=v4.0"; } foreach (EndpointConfig endpointConfig in endpointConfigs) { bool added = this.BaseAddEndpointConfig(config, endpointConfig); if (added) { this.svcFileManager.Add(endpointConfig.Appid, endpointConfig.Clsid); anyAdded = true; // the metadata exchange endpoint is not displayed as a regular endpoint if (endpointConfig.Iid == typeof(IMetadataExchange).GUID) { ToolConsole.WriteLine(SR.GetString(SR.MexEndpointAdded)); continue; } if (!Tool.Options.ShowGuids) { ToolConsole.WriteLine(SR.GetString(SR.InterfaceAdded, endpointConfig.ComponentProgID, endpointConfig.InterfaceName)); } else { ToolConsole.WriteLine(SR.GetString(SR.InterfaceAdded, endpointConfig.Clsid, endpointConfig.Iid)); } } else { // the metadata exchange endpoint is not displayed as a regular endpoint if (endpointConfig.Iid == typeof(IMetadataExchange).GUID) { if (!Tool.Options.ShowGuids) { ToolConsole.WriteWarning(SR.GetString(SR.MexEndpointAlreadyExposed, endpointConfig.ComponentProgID)); } else { ToolConsole.WriteWarning(SR.GetString(SR.MexEndpointAlreadyExposed, endpointConfig.Clsid)); } } else { if (!Tool.Options.ShowGuids) { ToolConsole.WriteWarning(SR.GetString(SR.InterfaceAlreadyExposed, endpointConfig.ComponentProgID, endpointConfig.InterfaceName)); } else { ToolConsole.WriteWarning(SR.GetString(SR.InterfaceAlreadyExposed, endpointConfig.Clsid, endpointConfig.Iid)); } } } } if (anyAdded) { WasModified = true; config.Save(); } }