As a developer, you do not have the source code for all the controls you use and even if you did, modifying it is not always the best way to override functionality. This is especially true if all you need to do is modify the rendered HTML. The architecture that drives the control adapters is built on the Adapter or Wrapper design pattern. The abstract class ControlAdapter defines the base functionality for all adapters. Classes like the Menu Adapter inherit from the WebControlAdapter to provide functionality specific to a control.
Figure 5 shows the class diagram for the control adapters. The implementation of this architecture is straightforward, especially for controls that already have adapters developed for them.
Fortunately, most all the ASP. NET controls do have adapters. The first step to accomplish this is to create or customize a browser definition file, which is used to detect the browser that is accessing the ASP. This is a good way to provide a customized experience to users coming to the site from mobile devices. For use with CSS Control Adapters, however, the browser definition file is used to signify that compliant browsers should use one or more adapters.
This would match most of the browsers used today. The browser definition file also gives you information you can use for all kinds of other customization of the user experience. The last step in implementing the CSS Control Adapter is to create a class that is derived from the adapter class. Figure 7 shows the example menu adapter that ships with the ASP. The class derives from the MenuAdapter class, enumerates through all of the items that make up the controls, and overrides the HTML with the appropriate tags.
Shown there is the portion of the class that renders the beginning of the unordered list in the BuildItems method. If you look at the HTML source in Figure 8 , you can see that the table from the menu control is replaced with an unordered list. The unordered list is not the only noteworthy topic in the HTML output, however.
The output is also noticeably cleaner because it is not cluttered with style and scripting code. All of the positioning and style now resides in the CSS file for the menu and the menu is now considered Web standards-compliant. The CSS Control Adapter comes with adapters for many controls, including for the Tree view, Login, and CreateUserWizard, which represent the controls that notoriously render tables when they should not.
It takes only a few minutes to integrate the samples into an existing project and customize to your liking. Now that you have the tools to render controls that comply with Web standards, you can make an entire site compliant. The combination of Master Pages and Themes provide a powerful and flexible infrastructure for a Web site. Master Pages allow Web developers to create flexible templates for Web pages. A powerful tool for creating reusable components across Web pages, Master Pages also provide a way to ensure standards compliance throughout a site.
For example, themes can improve accessibility for visually impaired users by letting them increase the font and image size. Placing the ability to switch themes within the Master Page allows users to view the site in a manner that best meets their individual needs.
One technique I find valuable to enable users to switch themes is to define a class that is derived from the Page class. The ability to switch themes is only available very early in the lifecycle of an ASP. The class in Figure 9 shows how to capture the theme a user has selected and apply it in the overridden method. This class is looking for a request form variable with a predefined name and passing the value to the theme class. All Web pages that implement this class will provide the infrastructure needed to enable multiple themes.
This is a very simple way to add theme switching to all pages on a site. This article discussed why Web standards are so important and looked at some techniques that can be used to create compliant Web sites. It can be challenging to adopt these standards because it is often not the easiest path to take, but it is the best way to ensure that the controls and HTML you build today will be accessible to a broader base of users on a larger number of devices in the future.
Browsers are increasingly conforming to these standards and will continue to do so; the burden now falls on the development community to produce Web standards-compliant code.
Depending on the environment, type of application, usage factors, etc. For the most part, however, most. NET applications and the programmers who write them just need the ability to store configuration Most configuration tends to be hierarchical and manual editing is usually desirable. This makes XML an ideal platform upon which to build a configuration storage framework. This also makes the. NET developer. Aside from being an application of XML and providing a hierarchical medium within which to store actual configuration settings, the.
Depending on the application context, a natural hierarchical order of multiple configuration files exists and are merged together when configuration is requested by code. This hierarchical structure to configuration files allows settings to be applied at various levels, from the entire machine, to the application and even down to the individual user or resource being requested. The hierarchical structure of the. A few important points to note about this diagram are the order in which configuration files are merged and the contexts within which configuration is available.
Depending on the context, the nature of what can be configured and how those settings are merged can differ in important ways. In the. Windows applications, or executables, have a relatively simple 4-layer configuration structure and merge process.
Web applications, on the other hand, have a more complex structure for applying and merging configuration for specific locations. These two primary types of applications each create a configuration context with the rules that govern how configuration is applied.
Independent of any context is machine-level configuration. Machine level configuration applies to any application that runs within the CLR, as well as the basic setup for all other configuration options that the. NET framework itself uses.
It may come as a surprise to many, but the. NET framework uses the same configuration framework discussed in this series of articles. It may further surprise many that none of the configuration capabilities observed within the.
NET framework are special or exclusive A quick examination of the machine. Things like appSettings, connectionStrings, system. Many default settings, such as section encryption providers, default ASP. NET membership, profile and role providers, etc. In the same directory, you should also notice commented versions of this file, a default version, as well as several default web.
While editing the machine. Below the machine level, configuration splits into the two available contexts Exe and Web. The Exe context is available to any executable application. Within this context, the core configuration infrastructure understands a total of four levels of configuration: Machine, Application, Roaming User and User.
Each level is subsequently more specific in "context. It is important to note that Roaming User configuration is less specific than User configuration. This allows user-specific settings to reside on both a desktop and a laptop independent of each other, while roaming settings are shared between the two and available on both. The Web context is available only to applications that run within an ASP.
Unlike the Exe context, which is process- and user-dependant, the Web context is location dependant. Configuration may target specific website locations either explicitly as configured in a web. Configuration on a per-user basis is generally unavailable in the Web configuration context, even if a user is properly authenticated. The hierarchical nature of. However, those configuration settings are not isolated and duplicate settings made at a more specific level have the ability to override settings made at a less specific level.
As can be seen in Figure 1 , the most specific configuration files are merged into the less specific, with the most specific settings overriding the least specific.
In the Exe context, User or to be more precise, Local User settings are most specific, followed by Roaming User shared between two or more machines , Application and, finally, Machine.
In the Web context, merging is a little more complex. The nuances of web. The configuration framework provides not only the means to implement custom configuration, but also provides the means to implement custom data validation and conversion, custom providers, exposes hooks for custom serialization and deserialization and even allows configuration to be encrypted.
Metadata about each configuration element is also exposed, providing details about the whats, wheres and hows of the data that was loaded. The architectural structure of the. The specifics of each element in the diagram will be the primary topic of this article as you read further. Hidden within this complicated looking diagram is an elegant, logical and efficient system for managing configuration.
I have tried to organize the individual components of this architecture into logical groups, which form the core sections of this article:. The first concept to be discussed in detail is also, logically, the first place you start when working with configuration in your projects. Configuration management, in the scope of this article, refers to finding configuration either directly, or by mapping to specific configuration files , retrieving configuration sections and the storage of those sections during use.
Mapping to specific configuration files differs depending on the context your operating under, but allows any configuration file to be loaded provided the necessary permissions to read from the resource are granted.
The ConfigurationManager and subsequently the WebConfigurationManager, are the primary starting points for accessing. The ConfigurationManager provides all of the core services required to retrieve configuration sections and the settings contained within them and also provides methods to allow configuration files to be explicitly loaded in the Exe context.
The WebConfigurationManager provides additional methods to explicitly load configuration in the Web context, while also acting as a proxy for common ConfigurationManager methods. These two static classes are diagramed below for reference. The primary functionality provided by the ConfigurationManager class, GetSection string sectionName , has been described in detail in the previous articles in this series and will not be reiterated here.
By default, the ConfigurationManager class provides implicit read-only access to configuration. Often, configuration needs extend beyond simply reading involatile settings and saving is required.
The ConfigurationManager exposes several methods to allow configuration files to be opened in a more explicit context. The first way of opening configuration is by using the ConfigurationManager. OpenExeConfiguration methods. There are two overloads of the OpenExeConfiguration method. One overload takes a string representing the path of the currently running executable and the other overload takes a ConfigurationUserLevel enumeration value.
The first method will append ". It's important to note that OpenExeConfiguration string exePath is a very misleading method, as the filename does not have to be the filename of the. One of the holy grails unattainable, as of yet Consider the following scenario:.
The solution to the above problem, which is one of the problems developers most frequently ask about, is OpenExeConfiguration string exePath. Consider this solution to the previous scenario:. The above scenario, which appears to be frequent enough, allows multiple configuration files specific to any assembly, not just the primary EXE to be used at the same time.
Any other code that must still access settings stored in Application. A simple proof of this concept can be demonstrated by the following code:. Despite its misleading signature and name, OpenExeConfiguration string exePath is an extremely powerful method capable of solving one of the more frequent configuration problems.
This method is also capable of loading configuration from HTTP paths as well, which is a possible scenario with ClickOnce smart client deployments. The second method, OpenExeConfiguration ConfigurationUserLevel level will load the appropriate configuration file for the specified configuration level.
Configuration levels, available in the Exe context, allow you to specify whether you want exe, roaming user, or local user configuration. The ConfigurationUserLevel enumeration is also a little misleading in how its values were named. This can lead to a misunderstanding of what the method does and what kind of configuration to expect as a result of calling it. The real meanings behind each value are as follows:.
Remember that configuration is hierarchical and merged. When requesting roaming or local user configuration, that level up through machine. An interesting consequence of this merging allows you to request roaming or local user configuration even when the User. The Configuration object returned will contain a FilePath that does not exist and the HasFile property will be false.
Any sections defined in higher configuration levels will still be accessible though and with the proper allowances, changes to those sections can be saved. Saving changes at a level that previously did not exist will create the appropriate User. Roaming and local user configuration settings are an interesting beast. Some of the more subtle behaviors of. In spite of their ugly heads, these subtle behaviors are another great reason to choose to use.
NET configuration framework provides some extensive security features that allow settings, sections and even section groups to be locked down absolutely, or depending on what level they are being accessed from. Consider the following code:. This example should open the local User. A value on this custom section is edited and the changes saved. The ultimate goal is to load any existing settings, or create the local User. This may seem simple, but depending on whether "customSection" was previously defined at the roaming, exe, or machine level, adding the section, or editing it if it already exists, may not be possible.
This scenario can happen fairly often and can become quite complex when a high volume of configuration is used. In addition to those just discussed, several other methods exist to open configuration files.
Using these methods, you can load an alternate machine. NET framework decide on some convaluted path , etc. When accessing machine. More details on how to use these methods and the corresponding ConfigurationFileMap classes, are available below in the ConfigurationFileMap class subsection. The last method exposed by the ConfigurationManager class, RefreshSection string sectionName , is another answer to one of the questions I more frequently get asked. There are times, however, when saved changes to configuration to not get picked up by the ConfigurationManager class especially in web environments.
There are many ways to solve such problems, but the simplest way is to call RefreshSection with the appropriate section name immediately after saving. This should force in most cases The ConfigurationManager class, while the first step to fully accessing your Exe context configuration, is woefully inadequate within the Web context. Unlike executable applications, web applications do not have a well identified local user for which User.
In fact, there can be no user specific configuration at all in a web application. Despite that, web configuration can be an even more complex beast when location-specific configuration is considered. Location specific configuration and how to use the WebConfigurationManager to take full advantage of it is nearly an article in and of itself. A complete discussion of the WebConfigurationManager and ConfigurationLocations , will be discussed in later sections of this article.
Additional file mapping classes, ExeConfigurationFileMap for the Exe context and WebConfigurationFileMap for the Web context, are required to load configuration beyond the machine level.
The ExeConfigurationFileMap allows you to specifically configure the exact pathnames to machine, exe, roaming and local configuration files, all together, or piecemeal, when calling OpenMappedExeConfiguration.
You are not required to specify all files, but all files will be identified and merged when the Configuration object is created. Showing results for. Show only Search instead for. Did you mean:. Roto Brush 2. Error or problem , Freeze or hang , Performance. Follow Report. Community guidelines. Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more. New Here , May 28, May 28, Jump to latest reply. Rick Gerard. Post Reply. Preview Exit Preview. You must be signed in to add attachments. Troubleshooting FAQs. Fix common After Effects crashes.
How to fix "Display Acceleration Disabled".
0コメント