Settings in web.config (2024)

  • Updated:
    • Settings in web.config (2)
    • Settings in web.config (3)

What is the web.config file

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. And the main benefit of this is, if we want to change some configuration settings then we do not need to restart our application to apply new changes, ASP.NET automatically detects the changes and applies them to the running ASP.NET application.

The ASP.NET framework uses a hierarchical configuration system. You can place a web.config file in any subdirectory of an application. The file then applies to any pages located in the same directory or any subdirectories.

web.config for nopCommerce

nopCommerce uses the web.config in the Nop.Web project which can be found inside the Presentation directory. In the root of the project directory, you can see a web.config file. If your solution is fresh installation of nopCommerce then the content of that file looks something like this:

<?xml version="1.0" encoding="utf-8"?><configuration> <system.webServer> <modules> <!-- Remove WebDAV module so that we can make DELETE requests --> <remove name="WebDAVModule" /> </modules> <handlers> <!-- Remove WebDAV module so that we can make DELETE requests --> <remove name="WebDAV" /> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <!-- When deploying on Azure, make sure that "dotnet" is installed and the path to it is registered in the PATH environment variable or specify the full path to it --> <aspNetCore requestTimeout="23:00:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" startupTimeLimit="3600" hostingModel="InProcess"> </aspNetCore> <httpProtocol> <customHeaders> <remove name="X-Powered-By" /> <!-- Protects against XSS injections. ref.: https://www.veracode.com/blog/2014/03/guidelines-for-setting-security-headers/ --> <add name="X-XSS-Protection" value="1; mode=block" /> <!-- Protects against Clickjacking attacks. ref.: http://stackoverflow.com/a/22105445/1233379 --> <add name="X-Frame-Options" value="SAMEORIGIN" /> <!-- Protects against MIME-type confusion attack. ref.: https://www.veracode.com/blog/2014/03/guidelines-for-setting-security-headers/ --> <add name="X-Content-Type-Options" value="nosniff" /> <!-- Protects against Clickjacking attacks. ref.: https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet --> <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" /> <!-- CSP modern XSS directive-based defence, used since 2014. ref.: http://content-security-policy.com/ --> <add name="Content-Security-Policy" value="default-src 'self'; connect-src *; font-src * data:; frame-src *; img-src * data:; media-src *; object-src *; script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline';" /> <!-- Prevents from leaking referrer data over insecure connections. ref.: https://scotthelme.co.uk/a-new-security-header-referrer-policy/ --> <add name="Referrer-Policy" value="same-origin" /> <!-- Permissions-Policy is a new header that allows a site to control which features and APIs can be used in the browser. ref.: https://w3c.github.io/webappsec-permissions-policy/ --> <add name="Permissions-Policy" value="accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=*, usb=()" /> </customHeaders> </httpProtocol> </system.webServer></configuration>
<configuration> ...</configuration>

Every configuration rule goes inside the "<configuration>" element.

<system.webServer> ...</system.webServer>

The <system.webServer> element specifies the root element for many of the site-level and application-level configuration settings for IIS, and contains configuration elements that define the settings used by the Web server engine and modules.

<modules> <!-- Remove WebDAV module so that we can make DELETE requests --> <remove name="WebDAVModule" /></modules>

The <modules> element defines the native-code modules and managed-code modules that are registered for an application. We commonly use modules to implement customized functionality.

The <modules> element contains a collection of <add>, <remove> and <clear> elements.

Here nopCommerce is using the <remove> element to remove the WebDAVModule module from the application.

<handlers> <!-- Remove WebDAV module so that we can make DELETE requests --> <remove name="WebDAV" /> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /></handlers>

Handlers are IIS components that are configured to process requests to specific content, typically to generate a response for the requested resource. For example, an ASP.NET Web page is one type of handler. You can use handlers to process requests to any resource that needs to return information to users that is not a static file.

The <handlers> element contains a collection of <add>, <remove>, and <clear> elements, each of which defines a handler mapping for the application. The <add> element adds a handler to the collection of handlers, the <remove> element removes references of the handler from the handler's collection, and the <clear> element removes all references of handlers from the handlers collection. Here in the above code "WebDAV" handler is removed and the handler for module AspNetCoreModuleV2 is added.

<aspNetCore requestTimeout="23:00:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" startupTimeLimit="3600" hostingModel="InProcess"/>
<httpProtocol> <customHeaders> <remove name="X-Powered-By" /> <!-- Protects against XSS injections. ref.: https://www.veracode.com/blog/2014/03/guidelines-for-setting-security-headers/ --> <add name="X-XSS-Protection" value="1; mode=block" /> <!-- Protects against Clickjacking attacks. ref.: http://stackoverflow.com/a/22105445/1233379 --> <add name="X-Frame-Options" value="SAMEORIGIN" /> <!-- Protects against MIME-type confusion attack. ref.: https://www.veracode.com/blog/2014/03/guidelines-for-setting-security-headers/ --> <add name="X-Content-Type-Options" value="nosniff" /> <!-- Protects against Clickjacking attacks. ref.: https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet --> <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" /> <!-- CSP modern XSS directive-based defence, used since 2014. ref.: http://content-security-policy.com/ --> <add name="Content-Security-Policy" value="default-src 'self'; connect-src *; font-src * data:; frame-src *; img-src * data:; media-src *; object-src *; script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline';" /> <!-- Prevents from leaking referrer data over insecure connections. ref.: https://scotthelme.co.uk/a-new-security-header-referrer-policy/ --> <add name="Referrer-Policy" value="same-origin" /> <!-- Permissions-Policy is a new header that allows a site to control which features and APIs can be used in the browser. ref.: https://w3c.github.io/webappsec-permissions-policy/ --> <add name="Permissions-Policy" value="accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=*, usb=()" /> </customHeaders> </httpProtocol>

The <customHeaders> element of the <httpProtocol> element specifies custom HTTP headers that IIS will return in HTTP responses from the Web server.

HTTP headers are name and value pairs that are returned in responses from a Web server. Custom response headers are sent to the client together with the default HTTP header. Unlike redirect response headers, which are returned in responses only when redirection occurs, custom response headers are returned in every response.

Configure the redirect rules in IIS

We can add other configurations additional to the above configurations. Here we will see how to configure redirect rules in IIS.

A redirect rule enables more than one URL to point to a single Web page. There may be several reasons why you want to redirect a request from one server to another. For example, maybe your company name is changed and you may want to register a new domain for your company and move your website to a new domain, so in that case, you may want to redirect all requests from your old domain to a new domain.

For our website to be able to use redirect rules, we need to install the "URL rewrite" module which is an extension to IIS.

For demonstration purposes, let's say we have to redirect a request from our old site to our new site, for that we need to write the following rules in our web.config file.

<rewrite> <rules> <rule name="[RULE NAME]" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny" trackAllCaptures="false"> <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" /> </conditions> <action type="Redirect" url="http://[NEW URL]/{R:1}" redirectType="Permanent"/> </rule> </rules></rewrite>
Note

By using this rule we can redirect all pages of an old domain name to the same page on a new domain name.

Here we need to replace [RULE NAME], [OLD URL], and [NEW URL] with the appropriate information.

  • [RULE NAME] can be anything that describes what this rule is doing
  • [OLD URL] is the old URL you want to redirect from.
  • [NEW URL] is the new URL you want to redirect to.
<match url="(.*)" />

The above element states that this rule will match all URL strings.

<add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />

The element above adds a condition to the rule that retrieves the host and requests Uri header value by reading the server variable HTTP_HOST and REQUEST_URI and matches it against the pattern with the value supplied for [OLD URL].

<action type="Redirect" url="http://[NEW URL]/{R:1}" redirectType="Permanent"/>

This element redirects the matching old URL to the new URL.

nopCommerce training course Start developing your skills and become a Certified Developer
Settings in web.config (2024)

FAQs

What is the Web config file settings? ›

A configuration file (web. config) is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way you can configure settings independently from your code.

Where do I put app settings in web config? ›

Locate the web. config file in the root directory of your application (or create one if it does not already exist). Add an <appSettings> element. Add <add> child elements along with key / value pairs to the <appSettings> element as required.

How do I open config settings? ›

To open a config file in Windows 10, you can:
  1. Type msconfig in the search box.
  2. Select System Configuration from the results.
  3. In the context menu, select Open with.
  4. Choose a text editor or configuration file editor.
  5. View and modify the contents of the config file.
Jun 6, 2022

What is the difference between web config and app settings? ›

App. config file is used to set configuration parameters externally for desktop / stand-alone applications. Web. config file is used to set configuration parameters externally for web applications.

What is the difference between config and settings? ›

Configuration- how you set up what an application does 'initially' - typically when you install it... Settings- how you change what an application does after it's been installed...

How to edit Web config? ›

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 to locate web config? ›

To find your website's configuration file, open the file manager and head to the public_html folder of your website. Most configuration files are located there, as it is the root directory of a website.

What are app configuration settings? ›

App Configuration helps you manage application settings and control their access centrally. It also simplifies your deployment tasks and eases the burden of dealing with permutations of configurations created by multiple applications, dependencies, and environments.

Where should web config go? ›

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.

What is default configuration settings? ›

Default configurations are the settings that come pre-installed on hardware, software, and systems straight out of the box.

How do I open and edit config files? ›

How to Edit a Configuration File in Windows
  1. Open the Windows start menu and type “wordpad” into the search bar. Right click on the WordPad icon in the start menu and click “Run as administrator” ...
  2. Select the file you want to edit in the list of files. ...
  3. The file you selected will open in WordPad allowing you to edit it.

Where is config located? ›

1 Answer. In your home folder ( ~ , usually /home/<username> ) the . config folder has lots of config files for many programs (some use other "hidden dotfiles" that begin with a dot, like . xxxx folders or files, also in the home folder) and often the desktop / display manager settings too.

What should be in web config? ›

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.

Is Web config safe? ›

Web. config files are protected by IIS, so clients cannot access it.

What is Web settings? ›

Website settings is a single place where various global and system-level content settings can be configured for your website's blog, navigation, pages, and themes.

Do I need a web config file? ›

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. This is because sensitive files exist on the app's physical path and if the web. config file is missing or named incorrectly, IIS may serve these files to the client.

How to see web config file in browser? ›

On a computer or other device connected to the same network as your product, open a web browser. Enter your product's IP address into the address bar. You see the available Web Config utility options.

What is the purpose of a config file? ›

In computing, configuration files (commonly known simply as config files) are files used to configure the parameters and initial settings for some computer programs or applications, server processes and operating system settings.

Should I delete config files? ›

If you want to make your database run faster and don't need the old configuration files, you could choose to delete them. For databases that aren't housed on fast servers, clearing off configuration history on a regular basis is a good idea.

Top Articles
15 Cheater's Guilt Signs You Should Look out For
Amazon Account Banned: Guide for Prevention and Resolution
Ross Dress For Less Hiring Near Me
Get train & bus departures - Android
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Craigslist Mexico Cancun
craigslist: south coast jobs, apartments, for sale, services, community, and events
Craigslist Dog Sitter
Truist Drive Through Hours
Weather Annapolis 10 Day
Mercy MyPay (Online Pay Stubs) / mercy-mypay-online-pay-stubs.pdf / PDF4PRO
The Blind Showtimes Near Showcase Cinemas Springdale
Top Hat Trailer Wiring Diagram
Günstige Angebote online shoppen - QVC.de
Facebook Marketplace Charlottesville
Washington, D.C. - Capital, Founding, Monumental
Simon Montefiore artikelen kopen? Alle artikelen online
978-0137606801
6813472639
Jackson Stevens Global
Zoe Mintz Adam Duritz
Tu Pulga Online Utah
Glover Park Community Garden
Home
Craigslist Pennsylvania Poconos
Raw Manga 1000
Papa Johns Mear Me
Cornedbeefapproved
O'reilly's In Monroe Georgia
A Man Called Otto Showtimes Near Carolina Mall Cinema
The Procurement Acronyms And Abbreviations That You Need To Know Short Forms Used In Procurement
Our 10 Best Selfcleaningcatlitterbox in the US - September 2024
Www Mydocbill Rada
Street Fighter 6 Nexus
Vlocity Clm
Ellafeet.official
Eero Optimize For Conferencing And Gaming
Mumu Player Pokemon Go
Nacogdoches, Texas: Step Back in Time in Texas' Oldest Town
Plato's Closet Mansfield Ohio
Selfservice Bright Lending
Western Gold Gateway
Has any non-Muslim here who read the Quran and unironically ENJOYED it?
Captain Billy's Whiz Bang, Vol 1, No. 11, August, 1920&#10;America's Magazine of Wit, Humor and Filosophy
Ursula Creed Datasheet
Sound Of Freedom Showtimes Near Amc Mountainside 10
Yale College Confidential 2027
Reilly Auto Parts Store Hours
Craigslist Charles Town West Virginia
Understanding & Applying Carroll's Pyramid of Corporate Social Responsibility
What your eye doctor knows about your health
Nkey rollover - Hitta bästa priset på Prisjakt
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6457

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.