How locate Web.config file

Oyeladun Ayobami 0 Reputation points
2025-04-02T05:51:37.73+00:00

Screenshot_20250402_063642_Chrome

This question is related to the following Learning Module

Developer technologies | ASP.NET | ASP.NET API
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 79,101 Reputation points Volunteer Moderator
    2025-04-02T16:37:26.1166667+00:00

    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.

    0 comments No comments

  2. 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

    1. Publish your application first (if you haven't already)
    2. Navigate to the publish output folder (usually bin/Release/net[version]/publish/ or similar)
    3. Look for the Web.config file - it should be automatically generated there
    4. 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:

    1. Right-click the Web.config file in Solution Explorer
    2. Select "Properties"
    3. Set "Copy to Output Directory" to "Copy always" or "Copy if newer"
    4. 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 and Startup.cs or Program.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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.