Asp.Net Core 2.0 Web应用程序的静态文件提供404 [英] Asp.Net Core 2.0 Web Application Static Files Gives 404

查看:104
本文介绍了Asp.Net Core 2.0 Web应用程序的静态文件提供404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Web服务器(asp.net core 2.0)获取自定义扩展名静态文件.

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

我尝试下一个:

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

因此,我可以在文件夹中看到我的文件,但是我找不到它-它抛出404:

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

当我单击它时:什么也没发生,我得到了404.

And when I click on it: nothing happened and I got 404.

已更新为Evk:

我将static_json.json文件添加到src文件夹中的静态文件中,并按预期得到了它:

I added static_json.json file to static files at src folder and it get it as expected:

谢谢您的帮助!

推荐答案

我不确定,但是您的扩展名似乎被IIS设置拒绝了,可以直接作为静态资源进行访问.请为web.config尝试以下操作:

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

这篇关于Asp.Net Core 2.0 Web应用程序的静态文件提供404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆