web.config file (2024)

  • Article

Note

This isn't the latest version of this article. For the current release, see the .NET 8 version of this article.

Warning

This version of ASP.NET Core is no longer supported. For more information, see .NET and .NET Core Support Policy. For the current release, see the .NET 8 version of this article.

Important

This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

For the current release, see the .NET 8 version of this article.

The web.config is a file that is read by IIS and the ASP.NET Core Module to configure an app hosted with IIS.

web.config file location

In order to set up the ASP.NET Core Module correctly, the web.config file must be present at the content root path (typically the app base path) of the deployed app. This is the same location as the website physical path provided to IIS. The web.config file is required at the root of the app to enable the publishing of multiple apps using Web Deploy.

Sensitive files exist on the app's physical path, such as {ASSEMBLY}.runtimeconfig.json, {ASSEMBLY}.xml (XML Documentation comments), and {ASSEMBLY}.deps.json, where the placeholder {ASSEMBLY} is the assembly name. When the web.config file is present and the site starts normally, IIS doesn't serve these sensitive files if they're requested. If the web.config file is missing, incorrectly named, or unable to configure the site for normal startup, IIS may serve sensitive files publicly.

The web.config file must be present in the deployment at all times, correctly named, and able to configure the site for normal start up. Never remove the web.config file from a production deployment.

If a web.config file isn't present in the project, the file is created with the correct processPath and arguments to configure the ASP.NET Core Module and moved to published output.

If a web.config file is present in the project, the file is transformed with the correct processPath and arguments to configure the ASP.NET Core Module and moved to published output. The transformation doesn't modify IIS configuration settings in the file.

The web.config file may provide additional IIS configuration settings that control active IIS modules. For information on IIS modules that are capable of processing requests with ASP.NET Core apps, see the IIS modules topic.

Creating, transforming, and publishing the web.config file is handled by an MSBuild target (_TransformWebConfig) when the project is published. This target is present in the Web SDK targets (Microsoft.NET.Sdk.Web). The SDK is set at the top of the project file:

<Project Sdk="Microsoft.NET.Sdk.Web">

To prevent the Web SDK from transforming the web.config file, use the <IsTransformWebConfigDisabled> property in the project file:

<PropertyGroup> <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled></PropertyGroup>

When disabling the Web SDK from transforming the file, the processPath and arguments should be manually set by the developer. For more information, see ASP.NET Core Module (ANCM) for IIS.

Configuration of ASP.NET Core Module with web.config

The ASP.NET Core Module is configured with the aspNetCore section of the system.webServer node in the site's web.config file.

The following web.config file is published for a framework-dependent deployment and configures the ASP.NET Core Module to handle site requests:

<?xml version="1.0" encoding="utf-8"?><configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> </system.webServer> </location></configuration>

The following web.config is published for a self-contained deployment:

<?xml version="1.0" encoding="utf-8"?><configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath=".\MyApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" /> </system.webServer> </location></configuration>

The InheritInChildApplications property is set to false to indicate that the settings specified within the <location> element aren't inherited by apps that reside in a subdirectory of the app.

When an app is deployed to Azure App Service, the stdoutLogFile path is set to \\?\%home%\LogFiles\stdout. The path saves stdout logs to the LogFiles folder, which is a location automatically created by the service.

For information on IIS sub-application configuration, see Advanced configuration.

Attributes of the aspNetCore element

AttributeDescriptionDefault
arguments

Optional string attribute.

Arguments to the executable specified in processPath.

disableStartUpErrorPage

Optional Boolean attribute.

If true, the 502.5 - Process Failure page is suppressed, and the 502 status code page configured in the web.config takes precedence.

false
forwardWindowsAuthToken

Optional Boolean attribute.

If true, the token is forwarded to the child process listening on %ASPNETCORE_PORT% as a header 'MS-ASPNETCORE-WINAUTHTOKEN' per request. It's the responsibility of that process to call CloseHandle on this token per request.

true
hostingModel

Optional string attribute.

Specifies the hosting model as in-process (InProcess/inprocess) or out-of-process (OutOfProcess/outofprocess).

OutOfProcess/outofprocess when not present
processesPerApplication

Optional integer attribute.

Specifies the number of instances of the process specified in the processPath setting that can be spun up per app.

†For in-process hosting, the value is limited to 1.

Setting processesPerApplication is discouraged. This attribute will be removed in a future release.

Default: 1
Min: 1
Max: 100
processPath

Required string attribute.

Path to the executable that launches a process listening for HTTP requests. Relative paths are supported. If the path begins with ., the path is considered to be relative to the site root.

rapidFailsPerMinute

Optional integer attribute.

Specifies the number of times the process specified in processPath is allowed to crash per minute. If this limit is exceeded, the module stops launching the process for the remainder of the minute.

Not supported with in-process hosting.

Default: 10
Min: 0
Max: 100
requestTimeout

Optional timespan attribute.

Specifies the duration for which the ASP.NET Core Module waits for a response from the process listening on %ASPNETCORE_PORT%.

In versions of the ASP.NET Core Module that shipped with the release of ASP.NET Core 2.1 or later, the requestTimeout is specified in hours, minutes, and seconds.

Doesn't apply to in-process hosting. For in-process hosting, the module waits for the app to process the request.

Valid values for minutes and seconds segments of the string are in the range 0-59. Use of 60 in the value for minutes or seconds results in a 500 - Internal Server Error.

Default: 00:02:00
Min: 00:00:00
Max: 360:00:00
shutdownTimeLimit

Optional integer attribute.

Duration in seconds that the module waits for the executable to gracefully shutdown when the app_offline.htm file is detected.

Default: 10
Min: 0
Max: 600
startupTimeLimit

Optional integer attribute.

Duration in seconds that the module waits for the executable to start a process listening on the port. If this time limit is exceeded, the module kills the process.

When hosting in-process: The process is not restarted and does not use the rapidFailsPerMinute setting.

When hosting out-of-process: The module attempts to relaunch the process when it receives a new request and continues to attempt to restart the process on subsequent incoming requests unless the app fails to start rapidFailsPerMinute number of times in the last rolling minute.

A value of 0 (zero) is not considered an infinite timeout.

Default: 120
Min: 0
Max: 3600
stdoutLogEnabled

Optional Boolean attribute.

If true, stdout and stderr for the process specified in processPath are redirected to the file specified in stdoutLogFile.

false
stdoutLogFile

Optional string attribute.

Specifies the relative or absolute file path for which stdout and stderr from the process specified in processPath are logged. Relative paths are relative to the root of the site. Any path starting with . are relative to the site root and all other paths are treated as absolute paths. Any folders provided in the path are created by the module when the log file is created. Using underscore delimiters, a timestamp, process ID, and file extension (.log) are added to the last segment of the stdoutLogFile path. If .\logs\stdout is supplied as a value, an example stdout log is saved as stdout_20180205194132_1934.log in the logs folder when saved on February 5, 2018 at 19:41:32 with a process ID of 1934.

aspnetcore-stdout

Set environment variables

Environment variables can be specified for the process in the processPath attribute. Specify an environment variable with the <environmentVariable> child element of an <environmentVariables> collection element. Environment variables set in this section take precedence over system environment variables.

The following example sets two environment variables in web.config. ASPNETCORE_ENVIRONMENT configures the app's environment to Development. A developer may temporarily set this value in the web.config file in order to force the Developer Exception Page to load when debugging an app exception. CONFIG_DIR is an example of a user-defined environment variable, where the developer has written code that reads the value on startup to form a path for loading the app's configuration file.

<aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess"> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> <environmentVariable name="CONFIG_DIR" value="f:\application_config" /> </environmentVariables></aspNetCore>

Note

An alternative to setting the environment directly in web.config is to include the <EnvironmentName> property in the publish profile (.pubxml) or project file. This approach sets the environment in web.config when the project is published:

<PropertyGroup> <EnvironmentName>Development</EnvironmentName></PropertyGroup>

Warning

Only set the ASPNETCORE_ENVIRONMENT environment variable to Development on staging and testing servers that aren't accessible to untrusted networks, such as the Internet.

Configuration of IIS with web.config

IIS configuration is influenced by the <system.webServer> section of web.config for IIS scenarios that are functional for ASP.NET Core apps with the ASP.NET Core Module. For example, IIS configuration is functional for dynamic compression. If IIS is configured at the server level to use dynamic compression, the <urlCompression> element in the app's web.config file can disable it for an ASP.NET Core app.

For more information, see the following topics:

To set environment variables for individual apps running in isolated app pools (supported for IIS 10.0 or later), see the AppCmd.exe command section of the Environment Variables <environmentVariables> topic in the IIS reference documentation.

Configuration sections of web.config

Configuration sections of ASP.NET 4.x apps in web.config aren't used by ASP.NET Core apps for configuration:

  • <system.web>
  • <appSettings>
  • <connectionStrings>
  • <location>

ASP.NET Core apps are configured using other configuration providers. For more information, see Configuration.

Transform web.config

If you need to transform web.config on publish, see Transform web.config. You might need to transform web.config on publish to set environment variables based on the configuration, profile, or environment.

Additional resources

web.config file (2024)

FAQs

What does a web config file contain? ›

web. config file is an XML-based configuration file used in ASP. NET-based applications to manage various settings that are concerned with the configuration of our website. In this way, we can separate our application logic from configuration logic.

How many web config files can I have in an solution? ›

You can have one Web. config file per folder . So in your root you can have a web. config and in a subfolder you can have another one that overrides settings from the one in the root.

How to solve cannot read configuration file due to insufficient permissions? ›

Solution 5
  1. 1.In Windows Explorer, locate the web. ...
  2. Right-click the web.config file.
  3. Click Properties.
  4. Click the Security tab, and then click Edit.
  5. Click Add.
  6. Enter the object name to select(example) Textbox will display for you type IIS_IUSRS and click check user button. ...
  7. Click OK.
Mar 17, 2012

Is it necessary to have web config? ›

The web. config file is required at the root of the app to enable the publishing of multiple apps using Web Deploy. Sensitive files exist on the app's physical path, such as {ASSEMBLY}. runtimeconfig.

What should a config file contain? ›

Each of the configuration files contains a list of configuration parameters and their arguments. Each parameter must be on a single line. Comments begin with the “#” character and terminate at the end of the same line.

What is stored in config file? ›

Config files store data for applications that enable users to interact with those applications in a specific and purposeful way. For example, if you're trying to configure a SQL (Structured Query Language) server, you may use a configuration file to determine which IP addresses can access the database.

What is the size limit for web config? ›

The default maximum limit is 250 KB. You can change this value by editing the registry key below (Reference). Make sure to restart the server after this change. If you have hundreds of URL Rewrite rules, you can create rewrite maps and store them in a separate file.

What is the maximum response size in web config? ›

Use the maxRequestLength property of the httpRuntime element. The default size is 4096 kilobytes (4MB). The maximum value is 2,147,483,647 kilobytes (~82 terabytes).

What is the size limit for config file? ›

config file exceeds 250 KB. Microsoft added this file size restriction to prevent attacker from uploading large config file to the server and start a possible Denial of Service (DOS) attack.

How do I override a config file? ›

Override configuration file settings on the command line

You can use the -o, --override command line option to override configuration file settings with key/value pairs. The key is the JSON path of the field to be overwritten.

How to ensure that the NTFS permissions for the web config file are correct and allow access to the web server's machine account? ›

NTFS permissions
  1. Open Windows Explorer. ...
  2. Expand My Computer.
  3. Right-click %systemroot%, and then click Properties.
  4. Click the Security tab, and then click Advanced.
  5. Double-click Permission, and then select the appropriate setting from the Apply Onto list.

How to enable detailed error information from the web config file? ›

Step 4: Modifying Error Handling Settings
  1. Locate the <system. web> section within the 'web. config' file. ...
  2. To enable detailed error messages, modify or add the following lines: <system.web> <!-- ...
  3. The <customErrors mode="Off" /> line turns off custom error messages, allowing detailed error messages to be displayed.

Where is my web config file? ›

The Web. config file is in the root directory of an ASP.NET application. The Web. config file specifies configuration information that is specific to the application.

How do I edit a web config file? ›

Editing the Configuration File (web. config)
  1. Open the Internet Information Services manager. ...
  2. Expand the Web Sites node, then expand the Default Web Site node.
  3. Right-click EFTAdHoc, then click Properties.
  4. In the Properties dialog box, click the ASP.NET tab. ...
  5. Click Edit Configuration. ...
  6. Click the General tab.
Jan 25, 2010

How do I set up a web config file? ›

To create a Web. config file
  1. In Solution Explorer, click the Refresh icon to make sure that a Web. ...
  2. In Solution Explorer, right-click your Web site name, and then click Add New Item.
  3. In the Templates window, click Web Configuration File. ...
  4. Click Add to create the file and open it for editing. ...
  5. If you have changed your Web.
Oct 22, 2014

What does a URLs config file contain? ›

config file. Within this file, there are configuration settings for both URLs and URL reservations. These configuration settings have very different purposes and rules for modification.

What are the parts of a config file? ›

Config files are typically written in plain text format and can be edited using any text editor. They often contain settings related to the user interface, operational parameters, system paths, and other options that might need to be customized to fit the needs of a particular environment or user preference.

Can we run an application without a web config file? ›

An application can execute without a web. config file, however, you cannot debug an application without a web. config file.

How to make a web config file? ›

To create a Web. config file
  1. In Solution Explorer, click the Refresh icon to make sure that a Web. ...
  2. In Solution Explorer, right-click your Web site name, and then click Add New Item.
  3. In the Templates window, click Web Configuration File. ...
  4. Click Add to create the file and open it for editing. ...
  5. If you have changed your Web.
Oct 22, 2014

Top Articles
404 Error Page
How to recover crypto you accidentally sent to the wrong network address
Navicent Human Resources Phone Number
Craigslist Home Health Care Jobs
Palm Coast Permits Online
Craigslist Cars Augusta Ga
Robot or human?
What Happened To Dr Ray On Dr Pol
What is the surrender charge on life insurance?
Tcu Jaggaer
Help with Choosing Parts
Jellyfin Ps5
Costco Great Oaks Gas Price
2024 INFINITI Q50 Specs, Trims, Dimensions & Prices
Melissababy
Food Universe Near Me Circular
Aes Salt Lake City Showdown
Minnick Funeral Home West Point Nebraska
Brbl Barber Shop
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
BJ 이름 찾는다 꼭 도와줘라 | 짤방 | 일베저장소
Craig Woolard Net Worth
Gilchrist Verband - Lumedis - Ihre Schulterspezialisten
Urbfsdreamgirl
Hwy 57 Nursery Michie Tn
Reserve A Room Ucla
Miles City Montana Craigslist
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Plasma Donation Racine Wi
Abga Gestation Calculator
Ff14 Laws Order
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
How does paysafecard work? The only guide you need
Pill 44615 Orange
Personalised Handmade 50th, 60th, 70th, 80th Birthday Card, Sister, Mum, Friend | eBay
Craigslist Pets Huntsville Alabama
Troy Gamefarm Prices
Rochester Ny Missed Connections
Michael Jordan: A timeline of the NBA legend
M Life Insider
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
How Does The Common App Work? A Guide To The Common App
Casamba Mobile Login
Mississippi weather man flees studio during tornado - video
Chathuram Movie Download
Joey Gentile Lpsg
Sarahbustani Boobs
Canvas Elms Umd
The Bold and the Beautiful
3367164101
Craigslist Chautauqua Ny
Raley Scrubs - Midtown
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6292

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.