.NET Core生产环境偶发405 Method Not Allowed错误排查求助
生产环境10%请求出现405/未知错误排查求助
生产环境中有10%的请求出现错误,本地环境及通过BrowserStack测试的多种浏览器、设备中均无法复现该问题。
错误信息
Sentry捕获的405错误
"errors": [ { "status": "405", "title": "Method Not Allowed", "detail": "HTTP method is not allowed" } ]
Angular浏览器控制台捕获的错误
"error": "[ProgressEvent]", "headers": "[ti]", "message": "Http failure response for https://api.xxxxxx:5000/api/public-web/files: 0 Unknown Error", "name": "HttpErrorResponse", "ok": false, "status": 0, "statusText": "Unknown Error", "url": "https://api.xxxxxx:5000/api/public-web/files"
注:实际请求地址为
POST https://api.jelenzatate.rs:5000/api/public-web/files/upload,日志来自Sentry。
技术栈
- .Net Core 6
- Angular 15 - Universal
- 服务器:Windows 2019 → IIS 10
已执行的排查操作
- 仅在IIS的web.config中配置了CORS自定义响应头,未在应用侧配置
- 尝试移除WEBDAV模块
- 在IIS中开启失败请求追踪和日志,但日志中未记录相关请求
相关配置
最初怀疑是CORS问题,因此在IIS的web.config中添加了以下响应头,完整配置如下:
<?xml version="1.0" encoding="utf-8"?> <configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <modules> <remove name="WebDAVModule"/> </modules> <httpProtocol> <customHeaders> <clear/> <add name="Access-Control-Allow-Origin" value="*"/> <add name="Access-Control-Allow-Methods" value="GET,POST,PATCH,PUT,DELETE,OPTIONS"/> <add name="Access-Control-Allow-Headers" value="*"/> </customHeaders> </httpProtocol> <handlers> <remove name="WebDAV"/> <add name="aspNetCore" path="*" verb="GET,POST,PATCH,PUT,DELETE" modules="AspNetCoreModuleV2" resourceType="Unspecified" requireAccess="None"/> </handlers> <aspNetCore processPath="dotnet" arguments="\.xxxx.Api.dll" stdoutLogEnabled="false" stdoutLogFile="\.\logs\stdout" hostingModel="inprocess"/> </system.webServer> </location> <system.webServer> <tracing> <traceFailedRequests> <add path="*"> <traceAreas> <add provider="ASP" verbosity="Verbose"/> <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose"/> <add provider="ISAPI Extension" verbosity="Verbose"/> <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket,ANCM,Rewrite,Cors,iisnode" verbosity="Verbose"/> </traceAreas> <failureDefinitions statusCodes="400-999"/> </add> </traceFailedRequests> </tracing> </system.webServer> </configuration>
.NET Core路由代码
[HttpPost("upload")] [DisableRequestSizeLimit] public async Task<IActionResult> Upload(IFormFile file, CancellationToken cancellationToken) { var fileDto = await _fileService.UploadApplicationDocument(file, cancellationToken); return ResponseObjectStatusCode(new ResponseObject<object>(fileDto)); }
目前观察到HTTP请求似乎根本没有到达服务器,请求协助排查该问题。
内容的提问来源于stack exchange,提问作者mmiroslav13
相关产品推荐
相关产品推荐

