Skip to content

"Minimal API" does not handle static files #33113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohnyL opened this issue May 28, 2021 · 2 comments
Closed

"Minimal API" does not handle static files #33113

JohnyL opened this issue May 28, 2021 · 2 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@JohnyL
Copy link

JohnyL commented May 28, 2021

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
@DamianEdwards
Copy link
Member

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

@JohnyL
Copy link
Author

JohnyL commented May 28, 2021

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

@DamianEdwards DamianEdwards added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label May 28, 2021
@ghost ghost added the Status: Resolved label May 28, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 27, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

4 participants