[英]Why am I getting “POST requests are not supported” in my Asp.Net Core log?
I have an ASP.NET Core 5 API setup.我有一个 ASP.NET Core 5 API 设置。 I also have a few Razor pages that use static content.
我还有一些使用静态内容的 Razor 页面。 I am using JWT for authentication.
我正在使用 JWT 进行身份验证。 In my
UserController
I have an action stub where I am developing a change password action:在我的
UserController
我有一个动作存根,我正在开发一个更改密码动作:
[Authorize]
[HttpPost("ChangePassword")]
public IActionResult ChangePassword([FromBody] string password)
{
HttpContext.Items.TryGetValue("User", out var user);
_logger.ForContext<UsersController>().Debug("User {EmailAddress} tried to change his password to {Password}.", ((User)user).EmailAddress, password);
return Ok();
}
This works and logs as tested with Swagger.这可以正常工作并记录使用 Swagger 进行测试。 I have other POST actions.
我还有其他 POST 操作。 This is the first time I try to get the user with
HttpContext
.这是我第一次尝试使用
HttpContext
获取用户。
However, only with this new Action, I get in my log two entries:但是,只有使用这个新操作,我才能在我的日志中获得两个条目:
23 Jul 2021 21:36:24.612 POST requests are not supported
2021 年 7 月 23 日 21:36:24.612 不支持 POST 请求
23 Jul 2021 21:36:24.605 POST requests are not supported2021 年 7 月 23 日 21:36:24.605 不支持 POST 请求
The log (Seq) shows the SourceContext
is Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware
.日志 (Seq) 显示
SourceContext
是Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware
。
I am wonder why I am getting these two log entries and can I safely ignore them?我想知道为什么我会收到这两个日志条目,我可以安全地忽略它们吗?
That log entry is coming from StaticFileMiddleware
checking if it should take over the request and return a file response.该日志条目来自
StaticFileMiddleware
检查它是否应该接管请求并返回文件响应。
public class StaticFileMiddleware
{
// ...
public Task Invoke(HttpContext context)
{
if (!ValidateNoEndpoint(context))
{
_logger.EndpointMatched();
}
else if (!ValidateMethod(context))
{
// 👇 "POST requests are not supported"
_logger.RequestMethodNotSupported(context.Request.Method);
}
else if (!ValidatePath(context, _matchUrl, out var subPath))
{
_logger.PathMismatch(subPath);
}
else if (!LookupContentType(_contentTypeProvider, _options, subPath, out var contentType))
{
_logger.FileTypeNotSupported(subPath);
}
else
{
// If we get here, we can try to serve the file
return TryServeStaticFile(context, contentType, subPath);
}
return _next(context);
}
}
Since it doesn't serve a static file, it calls the next middleware in the chain, which eventually lets the request be dispatched to your controller.由于它不提供静态文件,它调用链中的下一个中间件,最终让请求被分派到您的控制器。
You can safely ignore it.您可以放心地忽略它。 It's logged at
Debug
level and only matters if you're having problems with static files.它记录在
Debug
级别,仅当您遇到静态文件问题时才重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.