简书链接:中间件引发的错误SystemNotSupportedExceptionSpecifiedmethodisnotsupporte
文章字数:71,阅读全文大约需要1分钟
刚开始以为是我的接口请求出现的问题,

1
2
3
4
5
6
7

System.NotSupportedException: Specified method is not supported.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.set_Position(Int64 value)
at webapi.baseframework.auth.GlobalSQLInjectCheckMiddleware.InvokeAsync(HttpContext context) in
GlobalSQLInjectCheckMiddleware.cs:line 67
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

1
2
3
4
5
6
7
8
9

if (context.Request.Method == HttpMethods.Post && context.Request.ContentType?.StartsWith("application/json") == true)
{
using (var reader = new StreamReader(context.Request.Body))
{
var json = await reader.ReadToEndAsync();
context.Request.Body.Position = 0;
}
}

如果不是看到了这个对战错误包含了我的中间件,还不知道是这导致的,故这个地方进行调整,我这边先直接干掉。