Ran*_*ndy 3 c# jwt asp.net-core
我有一个 ASP.NET Core 5 API 设置。我还有一些使用静态内容的 Razor 页面。我正在使用 JWT 进行身份验证。在我的文件中,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();
}
Run Code Online (Sandbox Code Playgroud)
这可以通过 Swagger 测试并记录。我还有其他 POST 操作。这是我第一次尝试让用户使用HttpContext
.
然而,只有通过这个新操作,我才会在日志中收到两个条目:
2021年7月23日21:36:24.612 不支持POST请求
2021年7月23日21:36:24.605 不支持POST请求
日志 (Seq) 显示SourceContext
是Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware
。
我想知道为什么我会收到这两个日志条目,我可以安全地忽略它们吗?
该日志条目来自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);
}
}
Run Code Online (Sandbox Code Playgroud)
由于它不提供静态文件,因此它会调用链中的下一个中间件,最终将请求分派到您的控制器。
您可以安全地忽略它。它是在Debug
级别上记录的,并且仅在您遇到静态文件问题时才重要。
归档时间: |
|
查看次数: |
3322 次 |
最近记录: |