Search code examples
asp.net-core-webapihostingpleskwindows-serverasp.net-core-7.0

Deployment of ASP.NET Core Web API to PLESK


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=".\logs\stdout" />
        <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?


Solution

  • 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();