you appear to be using asp.net core. the web.config is created during publish if not in the project. copy the web.config from the publish folder to the project root folder. mark its build option to copy. then you can edit as suggested.
How locate Web.config file
This question is related to the following Learning Module
Developer technologies | ASP.NET | ASP.NET API
2 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 79,101 Reputation points Volunteer Moderator
2025-04-02T16:37:26.1166667+00:00 -
Danny Nguyen (WICLOUD CORPORATION) 725 Reputation points Microsoft External Staff
2025-07-10T04:21:17.4633333+00:00 Hi,
The error indicates that your ASP.NET Core application needs a Web.config file to configure custom error handling. In ASP.NET Core, the Web.config file is primarily used for IIS configuration when hosting on Windows servers.
How to Locate Web.config
Option 1: Find it in the Publish Folder
- Publish your application first (if you haven't already)
- Navigate to the publish output folder (usually
bin/Release/net[version]/publish/
or similar) - Look for the Web.config file - it should be automatically generated there
- Copy this Web.config file to your project's root directory (same level as your .csproj file)
Option 2: Create Web.config Manually
If you don't have a publish folder yet, create a new Web.config file in your project root with this basic structure:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\YourAppName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /> </system.webServer> </configuration>
Configure Build Settings
After adding the Web.config file to your project:
- Right-click the Web.config file in Solution Explorer
- Select "Properties"
- Set "Copy to Output Directory" to "Copy always" or "Copy if newer"
- Set "Build Action" to "Content"
Add Custom Error Configuration
To fix the specific error in your screenshot, modify the Web.config to include the customErrors section:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <customErrors mode="Off" /> </system.web> <system.webServer> <!-- IIS configuration here --> </system.webServer> </configuration>
Alternative: Use appsettings.json (Recommended)
For ASP.NET Core applications, it's often better to configure error handling in your
appsettings.json
andStartup.cs
orProgram.cs
files instead of relying on Web.config:{ "DetailedErrors": true, "Logging": { "LogLevel": { "Default": "Information" } } }
The Web.config approach is mainly needed when deploying to IIS or when you specifically need IIS-level configuration.