skip to Main Content

This is my web.config file (ASP.NET Core 7.0) :

<configuration>
    <system.webServer>
        <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="dotnet" arguments=".Test.dll" stdoutLogEnabled="false" stdoutLogFile=".logsstdout" />
        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

In this case I get a 404 error. But when I send request with Postman, I get the response.

If I remove this config:

    <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>

Index.html page entered as the website default page. But in this case when I send request with Postman, I can’t get a response.

How can I fix this?

1

Answers


  1. If you want to add a default html page, you should put it inside the asp.net core wwwroot folder and enable the static file middleware inside the program.cs.

    Like below:

    enter image description here

    Program.cs

    app.UseHttpsRedirection();
    //Use to host html pages.
    app.UseStaticFiles();
    
    app.UseRouting();
    
    
    app.UseAuthorization();
    app.UseSession();
    app.MapRazorPages();
    
    app.Run();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search