app.UseMiddleware< T>()导致500 [英] app.UseMiddleware<T>() causing 500

查看:232
本文介绍了app.UseMiddleware< T>()导致500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我直接在 startup.cs 中调用中间件,例如:

If I call the middleware directly in my startup.cs, e.g.:

public void Configure(IApplicationBuilder app)
{
    app.UseMiddleware<StaticFileMiddleware>();
    app.UseMiddleware<DefaultFilesMiddleware>();
}

查看源代码,这正是扩展方法正在调用的代码。但是,我遇到了500错误和堆栈跟踪:

Looking at the source on GitHub, this is exactly the code that the extension methods are calling. However, I'm getting a 500 error and a stack trace:

 :(
Oops.
500 Internal Server Error
System.InvalidOperationException
The 'Invoke' method's first argument must be of type 'HttpContext'.
at Microsoft.AspNetCore.Builder.<>c__DisplayClass3_0.<UseMiddleware>b__0(RequestDelegate next)
at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Show raw exception details

System.InvalidOperationException: The 'Invoke' method's first argument must be of type 'HttpContext'.
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass3_0.b__0(RequestDelegate next)
   at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

可能与我的没有可引用的静态文件扩展名问题。

无论哪种方式,我目前都无法获得一个简单的 index.html 页面来成功加载。

Either way, I currently can't get a simple index.html page to load successfully.

任何帮助?

谢谢

推荐答案

您可能正在使用RC1版本

You're probably using the RC1 version of the StaticFiles library inside of your project, instead of RC2.

在项目内部的StaticFiles库中,而不是RC2。在 project.json 中,更改以下内容:

In project.json, change this:

"dependencies": {
   "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
}

为此:

"dependencies": {
   "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final"
}

名称空间也已更改,但是一旦更正,您应该可以

The namespace also changed, but once that's corrected you should be good to go.

这篇关于app.UseMiddleware&lt; T&gt;()导致500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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