11

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!

7
  • Is this application IIS hosted? Commented Feb 25, 2018 at 10:38
  • @kuskmen Yes, just run it via debug. Just default project. Didn't change webroot folder location etc... Commented Feb 25, 2018 at 10:45
  • Where are the files you are trying to serve? UseStaticFiles() will serve by default files on wwwroot. If you are trying to serve files in a different folder, look at this: learn.microsoft.com/en-us/aspnet/core/fundamentals/… Commented Feb 25, 2018 at 11:02
  • So your question implies files with non-"custom" extensions do work? Like .txt files for example? Commented Feb 25, 2018 at 11:13
  • @jpgrassi Yes, I use default folder: wwwroot/src. As you can see browser detected this files like static content but it doesn't want to return it (and just throw 404) Commented Feb 25, 2018 at 11:50

3 Answers 3

21

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();
}
Sign up to request clarification or add additional context in comments.

Comments

7

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

Comments

0

This answer might come in late, but in my case the solution was in my IIS settings. JavaScript file extension (.js) is set to False in Allowed column of Request Filtering. Removing js file from Request Filtering solved this case for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.