繁体   English   中英

无法在ASP.NET Core中使用中间件

[英]Can't use middleware in ASP.NET Core

我正在按照Scott Allen的Pluralsight课程尝试组装一个ASP.NET Core小应用程序。 我在macOS上。

我的project.json依赖项如下所示:

        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        },
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
        "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"

我还原了所有必要的软件包。

我的Startup.cs看起来像这样:

...
 public void Configure(IApplicationBuilder app)
 {
      app.UseFileServer(); // 'IApplicationBuilder' does not contain a definition for 'UseFileServer' and no extension method 'UseFileServer' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?) [netcoreapp1.0]
      app.Run(context =>
      {
          return context.Response.WriteAsync("Hello from ASP.NET Core!");
       });
  }
...

我似乎已经具备所有依赖项,但是编译器抱怨没有看到任何中间件的扩展方法(例如UseFileServer

有任何想法吗?

您需要向project.json文件添加"Microsoft.AspNetCore.StaticFiles" : "1.0.0"依赖项,或者在单击Ctrl+.时遵循IDE的建议Ctrl+. 错误(不知道是否可以在Visual Studio Code中使用)。

另外,您可能必须包含Microsoft.AspNetCore.Builder命名空间,因为UseFileServer驻留在静态文件库中

暂无
暂无

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

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