简体   繁体   English

如何在 ASP.NET Core 1.0 中使用 UseStaticFiles

[英]How to use UseStaticFiles in ASP.NET Core 1.0

I can't find many proper Core 1.0 tutorials yet, but when I google the method name, I get umpteen examples that say to include in Startup.cs :我还找不到很多合适的 Core 1.0 教程,但是当我在 google 上搜索方法名称时,我得到了无数示例,这些示例说要包含在Startup.cs

app.UseDefaultFiles();
app.UseStaticFiles();

Yet I get compile errors that neither method exists on app , which is type IApplicationBuilder .然而,我收到编译错误,即app上不存在这两种方法,即IApplicationBuilder类型。 Are these calls no longer required, or named totally different, or set somewhere else?这些调用是否不再需要,或者命名完全不同,或者设置在其他地方?

You need to add你需要添加

"Microsoft.AspNetCore.StaticFiles": "1.0.0",

in your project.json here "1.0.0" is the version you want to use在您的project.json"1.0.0"是您要使用的版本

现在 1.0 版的正确参考是:

"Microsoft.AspNetCore.StaticFiles": "1.0.0"

in your project.json make sure you have a reference在你的 project.json 确保你有一个参考

"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"

in RC2 that will likely need to change to Microsoft.AspNetCore.StaticFiles在 RC2 中可能需要更改为 Microsoft.AspNetCore.StaticFiles

then you should be able to use那么你应该可以使用

app.UseStaticFiles();

要使用.csproj而不是project.json添加到 Asp.Net Core Web API 项目,您可以使用 Nuget 包管理器(搜索microsoft.aspnetcore.staticfiles )安装包。

直到今天它是Microsoft.AspNetCore.StaticFiles: 1.1.0

You must change Target framework in your project properties to .Net Core 2.0:您必须将项目属性中的 Target 框架更改为 .Net Core 2.0:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM