Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net Core 2.0 Web Application Static Files Gives 404

I try to get custom-extension static files from my web-server (asp.net core 2.0).

I try to run next:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDirectoryBrowser(); // just to see that I have this files 
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseStaticFiles();
        app.UseDirectoryBrowser();
    }
}

So, I can see my files at folders but I can't get it - it throw 404: my file in folder

And when I click on it: nothing happened and I got 404. enter image description here

Updated for Evk:

I added static_json.json file to static files at src folder and it get it as expected: But red one still not available

Thank you for any help in advance!

like image 466
pavel Avatar asked Feb 25 '18 10:02

pavel


2 Answers

I had the problem during development. I used the overloaded method of UseStaticFiles to set the option ServeUnknownFileTypes to true.

public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
    app.UseDeveloperExceptionPage()
        .UseSession()
        .UseStaticFiles(new StaticFileOptions
        {
            ServeUnknownFileTypes = true,
        })
        .UseDirectoryBrowser()
        .UseRequestLocalization()
        .UseMvcWithDefaultRoute();
}
like image 145
Zu1779 Avatar answered Sep 19 '22 00:09

Zu1779


I am not sure, but it looks like your extension is denied by IIS settings to access directly as a static resource. Please, try this for the web.config:

<configuration> 
   <system.webServer> 
       <security> 
          <requestFiltering> 
              <fileExtensions> 
                <add fileExtension=".appinstaller" allowed="true" /> 
              </fileExtensions> 
         </requestFiltering> 
       </security> 
    </system.webServer> 
</configuration> 

Also check request filtering. See more information: How to deny access to a specific file name extension

like image 34
Evgeny Gerbut Avatar answered Sep 20 '22 00:09

Evgeny Gerbut