Wednesday, July 16, 2008

Configuring Settings for ASP.NET Pages and Controls with IIS 7.0

Web applications that use ASP.NET include Web pages to provide the user interface and controls to provide drop-in functionality. As with ASP, you can optimize the way ASP.NET is used through a variety of configuration settings. You can also make additional functionality available by registering custom controls that applications can use.


Registering Custom Controls
Managed code applications can use any custom controls that are registered for use with IIS. As an administrator, you probably won't need to install controls, but you may need to validate control configurations. To view currently registered controls, in IIS Manager, navigate to the level of the configuration hierarchy you want to manage, double-click the Pages And Controls feature, and then in the Actions pane, click Register Controls. In the main pane, you should then see a list of the currently registered controls. Controls are listed by tag prefix, associated source or assembly, and entry type. Local entries are configured at the level you are working with. Inherited entries are configured at a higher level of the configuration hierarchy.

You can add a custom control by following these steps:
1. In IIS Manager, navigate to the level of the configuration hierarchy you want to manage, double-click the Pages And Controls feature, and then, in the Actions pane, click Register Controls.

2. In IIS Manager, on the Controls Page, click Add Custom Control. The Add Custom Control dialog box appears.

3. In the Tag Prefix text box, type the tag prefix assigned to the control, such as aspx.

4. In the Namespace text box, type the ASP.NET namespace in which the custom control type is defined, such as System.Web.UI.WebControls.WebParts.

5. In the Assembly text box, type the assembly details associated with the custom control. This includes the control's top-level namespace, version, culture, and any additional information required to register the assembly properly, such as its public key token. Then click OK.

You can edit registered control entries by clicking the control entry you want to modify and then clicking Edit. In the Edit Custom Control dialog box, modify the settings as necessary, and then click OK to save your changes. To remove a registration entry for a custom control that is no longer needed, click the control entry you want to remove, and then click Remove. When prompted to confirm the action, click Yes.


Configuring ASP.NET Settings for Pages and Controls
You can modify the way ASP.NET is used by Web applications by using the configuration settings on the Pages And Controls page in IIS Manager. To access this page, navigate to the level of the configuration hierarchy you want to manage, and then double-click the Pages And Controls feature.

The below are the available ASP.NET settings for pages and controls. In the related server, site, or application Web.config file, you manage these settings by using the sessionState configuration section.

• Base Type for Pages (pageBaseType) - Sets the base type that .aspx pages inherit by default. The default value in most cases is System.Web.UI.Page. This value can be overridden by the Inherits attribute.

• Base Type for User Controls (userControlBaseType) - Sets the base type that user controls inherit by default. The default value in most cases is System.Web.UI.UserControl.

• Buffer (buffer) - Determines whether .aspx pages and .ascx controls use response buffering. The default setting is True. When True, IIS uses response buffering in much the same way as it uses response buffering for ASP.

• Compilation Mode (compilationMode) - Determines whether an ASP.NET page or control should be compiled at run time. The default is Always, which ensures that pages and controls are always compiled at run time. A value of Never specifies that pages and controls are not compiled and should be interpreted instead. A value of Auto allows IIS to compile pages and controls as necessary and otherwise set them to be interpreted.

• Enable Authenticated View State (enableViewStateMAC) - Determines whether ASP.NET should run a message authentication code (MAC) on the page's view state when the page is posted back from the client. The default setting is True.

• Enable Session State (enableSessionState) - Specifies whether and how IIS maintains session state information for ASP.NET applications. The default setting is True. When True, IIS maintains session state information for ASP.NET. Alternately, you can use a value of ReadOnly to have IIS maintain non-editable, read-only session state data. If you don't want IIS to maintain session state information for ASP.NET, configure this setting to False.

• Enable View State (enableViewState) - Determines whether the page maintains the view state and the view state of any server controls it contains when the current page request ends. The default setting is True.

• Master Page File (masterPageFile) - Sets an optional master page path relative to the local configuration file. This allows applications to reference locations in the master page path by name rather than full file path.

• Maximum Page State Field Length (maxPageStateFieldLength) - Sets the maximum number of characters for individual view state fields. When the value is greater than zero (0), IIS breaks the view state field into chunks that are less than the specified length. Clients receive this chunked view state as a series of view state fields rather than a single, possibly very long view state field. When the value is set to -1, IIS does not chunk the view state field and instead sends the entire value to the client in a single view state field.

• Namespaces (namespaces) - Specifies the namespaces included for all pages. IIS imports these namespaces during assembly pre-compilation. If you expand the Namespaces node, you'll see a list of namespaces that will be imported.

• Style Sheet Theme (styleSheetTheme) - Sets the optional name of the theme folder that IIS will use to apply a theme before control declarations. You can specify a theme to apply after control declaration by using the theme attribute.

• Theme (theme) - Sets the optional name for the theme that is used for pages that are in the scope of the configuration file. The specified theme must exist as either an application or a global theme. If the theme does not exist, IIS generates an HttpException exception.

• Validate Request (validateRequest) - Determines whether ASP.NET validates requests to screen for potentially dangerous or malicious input. The default setting is True, which causes ASP.NET to validate input from client browsers. Although you should rarely disable validation, you can do so by using a value of False.


You can configure the list of namespaces that IIS imports during assembly pre-compilation by completing the following steps:

1. To view currently configured Pages And Controls settings, in IIS Manager, navigate to the level of the configuration hierarchy you want to manage, and then double-click the Pages And Controls feature.

2. On the Pages And Controls page, expand the Namespaces node to display a list of namespaces that will be included during assembly pre-compilation.

3. If you click the Namespaces entry, IIS Manager displays a selection button on the far right side of the second column. Clicking this button displays the String Collection Editor dialog box, which you can use to edit the imported namespace values. Edit the namespace entries as necessary. Add additional namespaces by typing each additional namespace on a separate line.

4. When you are finished editing namespace values, click OK. In the Actions pane, apply the changes to the configuration by clicking Apply.

No comments: