简体   繁体   中英

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 :

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

Yet I get compile errors that neither method exists on app , which is type 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

现在 1.0 版的正确参考是:

"Microsoft.AspNetCore.StaticFiles": "1.0.0"

in your project.json make sure you have a reference

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

in RC2 that will likely need to change to 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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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