Azure ASP.NET Core Web api 对于代理的多部分/表单数据请求返回 404
我是 Azure 新手,正在尝试设置我的 nextjs 客户端应用程序和 ASP.NET Core 后端应用程序。除了文件上传之外,现在一切似乎都运行良好。它在本地主机上工作,但在生产中,后端在到达实际的 API 端点之前返回 404 网页(附图)。我还成功测试了从我的计算机在 Postman 中发出多部分/表单数据 POST 请求。
我实现这一点的方法是,通过 api 路由(客户端的服务器端)将浏览器的上传代理到后端。我必须通过客户端服务器端从 httpOnly cookie 附加不记名令牌。
我已在 Startup.cs 中启用 CORS:
app.UseCors(builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); });
前端和后端应用程序在单独的服务中运行,我也尝试在 Azure 门户中启用 CORS,但在那里我只能允许来源,而不允许标头和方法?错误消息并不表明 CORS 问题,但我只是想确保..
据我所知,请求看起来不错,具有正确的 URL 和来源。我怀疑我在天蓝色中缺少一些配置,但按照错误消息中的提示我没有得到任何进一步的信息。
对可能导致这种情况的原因有什么建议吗?或者我可以从哪里开始寻找。我不太确定在哪里查找此问题的日志输出。
I'm new to Azure and trying to set up my nextjs client app and my ASP.NET Core backend app. Everything seems to play well now, except for file uploads. It's working on localhost, but in production the backend returns a 404 web page (attached image) before reaching the actual API endpoint. I've also successfully tested to make a multipart/form-data POST request in Postman from my computer.
The way I implemented this is that I'm proxying the upload from the browser through an api route (client's server side) to the backend. I have to go via the client server side to append a Bearer token from a httpOnly cookie.
I've enabled CORS in Startup.cs:
app.UseCors(builder => { builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); });
The frontend and backend apps are running in individual services and I've tried to enable CORS in the Azure portal as well, but there I could only allow origins, not headers and methods? The error message doesn't indicate CORS problems, but I just wanted make sure..
As far as I can see the requests look good, with correct URLs and origins. I suspect I'm missing some config in azure, but I didn't get any further by following the hints in the error message.
Any suggestions to what may cause this? Or where I can start looking. I'm not quite sure where to look for log output for this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于成功了。我认为代理 http 请求中的主机标头没有改变。我只更改了代理请求的 URL,但我也通过手动设置主机解决了这个问题。这也解释了为什么它在本地主机上工作,因为客户端和后端都在同一主机上运行。
I finally got this working. I figured the host header in the proxy http request was unchanged. I only changed the URL for the proxy request, but I solved it by setting the host manually as well. This also explains why it was working at localhost, since both the client and backend was running at the same host.