Skip to content

"Minimal API" does not handle static files #33113

Closed
@JohnyL

Description

@JohnyL

As announced here, ASP.NET Core introduces minimal API for creating web apps. I decided to try it out with two simple test apps.

1. Serving plain index.html file

Here's the sample project. Does not work. I get error: This localhost page can't be found.
Upon investigation I found out that WebRootPath is the same as ContentRootPath (according to web root definition, web root path is, by default, content path plus wwwroot):

var builder = WebApplication.CreateBuilder(args);
var contentRootPath = builder.Environment.ContentRootPath; // C:\minapi
var webRootPath = builder.Environment.WebRootPath;         // C:\minapi

Changing WebRootPath to C:\minapi\wwwroot didn't work:

builder.Environment.WebRootPath = Path.Combine(builder.Environment.ContentRootPath, "wwwroot");

2. Razor Pages

This time I have included Razor Pages (sample project). This time things got interesting: the razor page was successfully generated, it appeared in browser, but neither Bootstrap file nor JavaScript file were served!
image
image

Further technical details

  • ASP.NET Core version: 6.0.100-preview.4.21255.9

  • Include the output of dotnet --info

    Output

    .NET SDK (reflecting any global.json):
    Version: 6.0.100-preview.4.21255.9
    Commit: 950e4949a7

    Runtime Environment:
    OS Name: Windows
    OS Version: 10.0.19043
    OS Platform: Windows
    RID: win10-x64
    Base Path: C:\Program Files\dotnet\sdk\6.0.100-preview.4.21255.9\

    Host (useful for support):
    Version: 6.0.0-preview.4.21253.7
    Commit: bfd6048a60

    .NET SDKs installed:
    5.0.102 [C:\Program Files\dotnet\sdk]
    5.0.202 [C:\Program Files\dotnet\sdk]
    5.0.300-preview.21258.4 [C:\Program Files\dotnet\sdk]
    6.0.100-preview.4.21255.9 [C:\Program Files\dotnet\sdk]

    .NET runtimes installed:
    Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.0-preview.3.21201.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.0-preview.4.21253.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.0-preview.3.21201.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.0-preview.4.21253.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.0-preview.3.21201.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.0-preview.4.21254.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • The IDE (VS / VS Code/ VS4Mac): Visual Studio Community 2019 Preview 16.11.0 Preview 1.0

Activity

DamianEdwards

DamianEdwards commented on May 28, 2021

@DamianEdwards
Member

Likely dupe of #32415. See that issue for workaround until a preview with the fix ships.

JohnyL

JohnyL commented on May 28, 2021

@JohnyL
Author

@DamianEdwards Thanks, Damian, the workaround worked perfectly! 😎

ghost locked as resolved and limited conversation to collaborators on Jun 27, 2021
added
area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
and removed on Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: DuplicateResolved as a duplicate of another issueStatus: Resolvedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DamianEdwards@Tratcher@JohnyL@amcasey

        Issue actions

          "Minimal API" does not handle static files · Issue #33113 · dotnet/aspnetcore