{"id":1086,"date":"2010-09-24T09:24:25","date_gmt":"2010-09-24T08:24:25","guid":{"rendered":"http:\/\/www.galhano.com\/blog\/?p=1086"},"modified":"2010-09-24T09:24:25","modified_gmt":"2010-09-24T08:24:25","slug":"aspnet-web-configuration-guidelines","status":"publish","type":"post","link":"http:\/\/galhano.com\/blog\/?p=1086","title":{"rendered":"ASP.NET Web Configuration Guidelines"},"content":{"rendered":"<div class=\"lw_vs\">\n<div id=\"curversion\"><strong> .NET Framework 4<\/strong><\/div>\n<\/div>\n<div class=\"introduction\">\n<p>ASP.NET  enables you to specify configuration settings that affect all Web  applications on a server, that affect only a single application, that  affect individual pages, or that affect individual folders in a Web  application. You can make configuration settings for features such as  compiler options, debugging, user authentication, error-message display,  connection strings, and more.<\/p>\n<p>Configuration data is stored in XML files that are named Web.config.<\/p>\n<p>This  topic describes the main configuration settings that you can make in  the Web.config file. The topic contains the following sections:<\/p>\n<ul>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff400235%28VS.100%29.aspx#configuration_sections\">Configuration File Sections<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff400235%28VS.100%29.aspx#modifying_the_configuration_files\">Modifying Configuration Files<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff400235%28VS.100%29.aspx#configuration_files_hierarchy\">Configuration Files Hierarchy<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff400235%28VS.100%29.aspx#deploying_configuration_files\">Deploying Configuration Files<\/a><\/li>\n<\/ul>\n<p><!--more--><\/div>\n<div class=\"LW_CollapsibleArea_Container\">\n<div class=\"LW_CollapsibleArea_TitleDiv\"><span class=\"LW_CollapsibleArea_Title\">Configuration File Sections<\/span><\/p>\n<div class=\"LW_CollapsibleArea_HrDiv\">\n<hr class=\"LW_CollapsibleArea_Hr\" \/><\/div>\n<\/div>\n<p>Configuration files are grouped into sections that contain the settings for individual features.<\/p>\n<h3 class=\"subHeading\">Compilation<\/h3>\n<div class=\"subsection\">\n<p>In order for an application to service Web requests, ASP.NET must first compile the application into one or more assemblies.<\/p>\n<p>You use the <span><span class=\"input\">compilation<\/span><\/span> configuration section to configure the settings that ASP.NET requires  in order to compile Web applications. The following are some of the  attributes that you can specify:<\/p>\n<ul>\n<li><span><span class=\"input\">debug<\/span><\/span>. During the development stage, you can set the <span><span class=\"input\">debug<\/span><\/span> attribute to <span><span class=\"input\">true<\/span><\/span> to generate the symbols that are required during debugging. At the end of the development cycle, you set the <span><span class=\"input\">debug<\/span><\/span> attribute to <span><span class=\"input\">false<\/span><\/span> in order to optimize performance<\/li>\n<li><span><span class=\"input\">targetFramework<\/span><\/span>.  This attribute specifies the version of the .NET Framework that the Web  site targets. This attribute should be included only for Web sites that  target the .NET Framework 4 and later versions. It is used by Visual  Studio to make sure that your project uses only features that are  available in the targeted framework version. For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb398791.aspx\">.NET Framework Multi-Targeting for ASP.NET Web Projects<\/a><\/span>.<\/li>\n<\/ul>\n<p>The following example shows how to specify configuration settings in the <span><span class=\"input\">compilation<\/span><\/span> section. The configuration settings specify that debugging symbols  should be generated, that changed files must be recompiled, and that the  target version is .NET Framework 4.<\/p>\n<div class=\"LW_CodeSnippetContainer\"><a name=\"CodeSpippet0\"><\/a><\/p>\n<div class=\"LW_CodeSnippetContainerCodeCollection\">\n<div class=\"LW_CodeSnippetToolBar\">\n<div class=\"LW_CodeSnippetToolBarText\"><a title=\"Copy to clipboard.\">Copy<\/a><\/div>\n<\/div>\n<div id=\"CodeSnippetContainerCode0\" class=\"LW_CodeSnippetContainerCode\">\n<div style=\"color: black;\">\n<pre>&lt;compilation debug=\"true\" \r\n    optimizeCompilations=\"true\" \r\n    targetFramework=\"4.0\" \/&gt;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/s10awwz0.aspx\">compilation Element (ASP.NET Settings Schema)<\/a><\/span>. For information about compilation, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms178466.aspx\">ASP.NET Compilation Overview<\/a><\/span>.<\/div>\n<h3 class=\"subHeading\">Custom Errors<\/h3>\n<div class=\"subsection\">\n<p>You  can configure how information is displayed by ASP.NET when unhandled  errors occur during the execution of a Web request. You might to do this  to provide additional information to the user, or to customize the  standard message that is displayed by ASP.NET. The following are some of  the attributes that you can specify:<\/p>\n<ul>\n<li><span><span class=\"input\">mode<\/span><\/span>.  Specifies whether custom errors are enabled or disabled, or that  verbose error messages are disabled if the error is being viewed on a  computer other than the server itself. You can set <span><span class=\"input\">mode<\/span><\/span> to the following values:\n<ul>\n<li><span><span class=\"input\">On<\/span><\/span>. Specifies that custom errors are enabled. If no <span><span class=\"input\">defaultRedirect<\/span><\/span> attribute is specified, users see a generic error. The custom errors are shown to the remote clients and to the local host.<\/li>\n<li><span><span class=\"input\">Off<\/span><\/span>. Specifies that custom errors are disabled. Detailed ASP.NET errors are shown to the remote clients and to the local host.<\/li>\n<li><span><span class=\"input\">RemoteOnly<\/span><\/span>.  Specifies that custom errors are shown only to the remote clients, and  that detailed ASP.NET errors are shown to the local host. This is the  default value.<\/li>\n<\/ul>\n<\/li>\n<li><span><span class=\"input\">defaulRedirect<\/span><\/span>.  Specifies the default URL to direct a browser to if an error occurs.  When this attribute is not specified, a generic error is displayed  instead.<\/li>\n<li><span><span class=\"input\">redirectMode<\/span><\/span>. Specifies values for how the URL of the original request is handled when a custom error page is displayed.<\/li>\n<\/ul>\n<p>The  following example shows how to configure error handling. The settings  specify that custom errors are displayed only on remote client  computers. The GenericErrorPage.htm page is displayed when an  unspecified error occurs. The pages NoAccess.htm and FileNotFound.htm  are displayed if HTTP 403 (Forbidden) or HTTP 404 (Not Found) errors  occur when users request resources that are managed by ASP.NET.<\/p>\n<div class=\"LW_CodeSnippetContainer\"><a name=\"CodeSpippet1\"><\/a><\/p>\n<div class=\"LW_CodeSnippetContainerCodeCollection\">\n<div class=\"LW_CodeSnippetToolBar\">\n<div class=\"LW_CodeSnippetToolBarText\"><a title=\"Copy to clipboard.\">Copy<\/a><\/div>\n<\/div>\n<div id=\"CodeSnippetContainerCode1\" class=\"LW_CodeSnippetContainerCode\">\n<div style=\"color: black;\">\n<pre>&lt;customErrors mode=\"RemoteOnly\"     \r\n    defaultRedirect=\"GenericErrorPage.htm\"&gt;\r\n  &lt;error statusCode=\"403\" redirect=\"NoAccess.htm\" \/&gt;\r\n  &lt;error statusCode=\"404\" redirect=\"FileNotFound.htm\" \/&gt;\r\n&lt;\/customErrors&gt;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/h0hfz6fc.aspx\">customErrors Element (ASP.NET Settings Schema)<\/a><\/span>.<\/div>\n<h3 class=\"subHeading\">Authentication and Roles<\/h3>\n<div class=\"subsection\">\n<p>ASP.NET can authenticate the credentials, such as name and password, of a Web site user. By using <span><span class=\"input\">mode<\/span><\/span> attribute in the <span><span class=\"input\">authentication<\/span><\/span> configuration section, you can specify the authentication scheme for  your application. The default is Windows authentication, where the  Windows user&#8217;s account information is used for authentication. This can  be a valid choice for intranet users. In case of Internet users, you  must use a different scheme, such as ASP.NET forms authentication.<\/p>\n<p>The following example specifies that Web site users are authenticated by using the Windows authentication scheme:<\/p>\n<div class=\"LW_CodeSnippetContainer\"><a name=\"CodeSpippet2\"><\/a><\/p>\n<div class=\"LW_CodeSnippetContainerCodeCollection\">\n<div class=\"LW_CodeSnippetToolBar\">\n<div class=\"LW_CodeSnippetToolBarText\"><a title=\"Copy to clipboard.\">Copy<\/a><\/div>\n<\/div>\n<div id=\"CodeSnippetContainerCode2\" class=\"LW_CodeSnippetContainerCode\">\n<div style=\"color: black;\">\n<pre>&lt;authentication mode=\"Windows\"\/&gt;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>The authentication configuration section provides a variety of ways to configure authorization rules for users based on roles.<\/p>\n<p>For more information, see the following topics:<\/p>\n<ul>\n<li><span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/532aee0e.aspx\">authentication Element (ASP.NET Settings Schema)<\/a><\/span><\/li>\n<li><span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/8d82143t.aspx\">authorization Element (ASP.NET Settings Schema)<\/a><\/span>.<\/li>\n<li><span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/330a99hc.aspx\">ASP.NET Web Application Security<\/a><\/span><\/li>\n<\/ul>\n<\/div>\n<h3 class=\"subHeading\">IIS 7 and ASP.NET Ajax<\/h3>\n<div class=\"subsection\">\n<p>The <span><span class=\"input\">system.webServer<\/span><\/span> configuration section defines the settings for IIS 7.0 that are applied  to a Web application. This section is required for running ASP.NET Ajax  under Internet Information Services (IIS) 7. It is not required for  earlier versions of IIS.<\/p>\n<p>For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb763179.aspx\">How to: Configure the &lt;system.webServer&gt; Section for IIS 7.0<\/a><\/span>.<\/div>\n<h3 class=\"subHeading\">Connection Strings<\/h3>\n<div class=\"subsection\">\n<p>The <span><span class=\"input\">connectionStrings<\/span><\/span> configuration section specifies a collection of database connection  strings. The following example shows how to specify a connection string.  The settings specify the connection string name, the server that hosts  the database, the name of the database, and the user credentials to  access the database.<\/p>\n<div class=\"LW_CodeSnippetContainer\"><a name=\"CodeSpippet3\"><\/a><\/p>\n<div class=\"LW_CodeSnippetContainerCodeCollection\">\n<div class=\"LW_CodeSnippetToolBar\">\n<div class=\"LW_CodeSnippetToolBarText\"><a title=\"Copy to clipboard.\">Copy<\/a><\/div>\n<\/div>\n<div id=\"CodeSnippetContainerCode3\" class=\"LW_CodeSnippetContainerCode\">\n<div style=\"color: black;\">\n<pre>&lt;connectionStrings&gt;\r\n  &lt;add name=\"Sales\" \r\n       connectionString=\r\n         \"server=myserver;database=Products;\r\n         uid=&lt;user name&gt;;pwd=&lt;secure password&gt;\" \/&gt;\r\n&lt;\/connectionStrings&gt;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bf7sd233.aspx\">connectionStrings Element (ASP.NET Settings Schema)<\/a><\/span>. For more information about accessing data sources, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms178359.aspx\">ASP.NET Data Access Overview<\/a><\/span>.<\/div>\n<\/div>\n<div class=\"LW_CollapsibleArea_Container\">\n<div class=\"LW_CollapsibleArea_TitleDiv\"><span class=\"LW_CollapsibleArea_Title\">Modifying Configuration Files<\/span><\/p>\n<div class=\"LW_CollapsibleArea_HrDiv\">\n<hr class=\"LW_CollapsibleArea_Hr\" \/><\/div>\n<\/div>\n<p>When  you use Visual Studio 2010 to create a new Web site project or Web  application project, a Web.config file is included in the new project.  You can create or modify configuration settings in the following ways:<\/p>\n<ul>\n<li>By  using a text editor or an XML editor to change the configuration files.  For information about syntax, see the configuration reference topics in  <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/b5ysx397.aspx\">ASP.NET Configuration Settings<\/a><\/span> and <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms228112.aspx\">General Configuration Settings (ASP.NET)<\/a><\/span>.<\/li>\n<li>In IIS 6 by using the ASP.NET MMC snap-in. You can start the MMC snap-in from the Web site properties dialog box.<\/li>\n<li>In IIS  7 by using the IIS Configuration Editor. You can start the editor from IIS Manager under <span class=\"label\">Server Component<\/span>. For more information, see <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=186794\">IIS Configuration Editor<\/a> on the TechNet Web site and <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=186793\">Editing Collections with the IIS Configuration Editor<\/a> on the IIS.net Web site.<\/li>\n<li>By using the Web Site Administration Tool in Visual Studio. For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms228053.aspx\">ASP.NET Web Site Administration Tool<\/a><\/span>.<\/li>\n<\/ul>\n<p>For more information about modifying configuration settings, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ackhksh7.aspx\">Editing ASP.NET Configuration Files<\/a><\/span>.<\/p>\n<p>You  can also create and modify the configuration settings programmatically  by using the ASP.NET configuration API. For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms178688.aspx\">ASP.NET Configuration API<\/a><\/span>.<\/div>\n<div class=\"LW_CollapsibleArea_Container\">\n<div class=\"LW_CollapsibleArea_TitleDiv\"><span class=\"LW_CollapsibleArea_Title\">Configuration Files Hierarchy<\/span><\/p>\n<div class=\"LW_CollapsibleArea_HrDiv\">\n<hr class=\"LW_CollapsibleArea_Hr\" \/><\/div>\n<\/div>\n<p>All  .NET Framework applications inherit basic configuration settings and  defaults from the Machine.config file that is used for server-wide  configuration settings. These settings apply to all .NET Framework  applications (including ASP.NET applications) that run on that server.<\/p>\n<p>The  root of the ASP.NET configuration hierarchy is the Web.config file that  is located in the same directory as the Machine.config file. The root  Web.config file inherits all the settings in the Machine.config file. It  includes settings that apply to all of the ASP.NET applications that  run a specific version of the .NET Framework.<\/p>\n<p>Because  each ASP.NET application inherits default configuration settings from  the root Web.config file, you need to create Web.config files only for  settings that you want to override. You can create the following Web  configuration files:<\/p>\n<ul>\n<li>A  Web.config file for a specific ASP.NET application. This file is in the  root directory of the application and contains settings that apply to  that Web application. Settings in this file are inherited by any  subdirectories in the application.<\/li>\n<li>The Web.config file  for an application subdirectory. This file contains settings that apply  to that subdirectory and its children (if any).<\/li>\n<\/ul>\n<p>This  hierarchy structure enables you to set configuration details for your  applications at the appropriate directory levels without affecting  configuration settings at higher level. For more information, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms178685.aspx\">ASP.NET Configuration File Hierarchy and Inheritance<\/a><\/span>.<\/div>\n<div class=\"LW_CollapsibleArea_Container\">\n<div class=\"LW_CollapsibleArea_TitleDiv\"><span class=\"LW_CollapsibleArea_Title\">Deploying Configuration Files<\/span><\/p>\n<div class=\"LW_CollapsibleArea_HrDiv\">\n<hr class=\"LW_CollapsibleArea_Hr\" \/><\/div>\n<\/div>\n<p>When  you deploy a Web site, often you want some settings in the deployed  application&#8217;s Web.config to be different than those in the development  Web.config file. For example, on a production server, you might want to  disable debug options and change connection strings so that they point  to different databases. For Web application projects, you can create a  Web.config transform file that is applied automatically during  deployment in order to change the deployed versions of Web.config files.<\/p>\n<p>For information about the difference between Web application projects and Web site projects, see <span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd547590.aspx\">Web Application Projects versus Web Site Projects<\/a><\/span>.<\/p>\n<p>source link: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff400235%28VS.100%29.aspx\" target=\"_blank\">http:\/\/msdn.microsoft.com\/en-us\/library\/ff400235%28VS.100%29.aspx<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>.NET Framework 4 ASP.NET enables you to specify configuration settings that affect all Web applications on a server, that affect only a single application, that affect individual pages, or that affect individual folders in a Web application. You can make configuration settings for features such as compiler options, debugging, user authentication, error-message display, connection strings, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,28,22],"tags":[115],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-netfx","category-aspnet-20","category-microsoft","tag-add-new-tag","author-admin"],"_links":{"self":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1086"}],"version-history":[{"count":2,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1088,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1086\/revisions\/1088"}],"wp:attachment":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}