美文网首页.NET程序员
asp.net core mvc 读取静态文件

asp.net core mvc 读取静态文件

作者: 大坤儿 | 来源:发表于2018-07-30 10:06 被阅读6次

在Startup.cs文件中,找到Configure方法,在里面添加以下代码即可。

            {
                FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), @"Common")),
                RequestPath = new PathString("/Common"),
                ContentTypeProvider = new FileExtensionContentTypeProvider(
                new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { ".js", "application/javascript" },
                    { ".css", "text/css" },
                    { ".png", "" },
                    { ".jpg", "" },
                    { ".woff2", "" },
                    { ".woff", "" },
                    { ".ttf", "" }
                })
            });

注:1.@“Common” 指需要自己在mvc项目中自己创建文件夹,文件夹名为Common。
2.{ ".png", "" },代表静态文件的词缀。

相关文章

网友评论

    本文标题:asp.net core mvc 读取静态文件

    本文链接:https://www.haomeiwen.com/subject/ttmxvftx.html