简体   繁体   English

路由 URL 中的电子邮件地址在 Asp.Net Core Web Api 中给出 403 错误

[英]Email Address in Route URL giving 403 error in Asp.Net Core Web Api

I have Web API Project using ASP.Net Core 5.0 This is my GET API URL:我有使用 ASP.Net Core 5.0 的 Web API 项目 这是我的 GET API URL:

https://myapi.project.com/api/name@email.com https://myapi.project.com/api/name@email.com

Its returning me 403 Forbidden Access Denied Error because may be name@email.com is changing into name%40email.com but when i add one more parameter in the end then it works fine.它返回给我 403 Forbidden Access Denied Error 因为可能是 name@email.com 正在更改为 name%40email.com 但是当我最后添加一个参数时它工作正常。 For Example:例如:

https://myapi.project.com/api/name@email.com/SomeParameter it works fine here. https://myapi.project.com/api/name@email.com/SomeParameter它在这里工作正常。

Can anyone please help me how I can resolve Email Address properly in GET API Routing.任何人都可以帮助我如何在 GET API 路由中正确解析电子邮件地址。

Thank You谢谢你

What happens is that your request gets urlencoded, which aims at removing or replacing things that can have another meaning.发生的情况是您的请求被 urlencoded,其目的是删除或替换可能具有其他含义的内容。

normally your controller will handle this with no effort required on your behalf, but you can decode it server side using通常,您的控制器会代表您无需任何努力即可处理此问题,但您可以使用服务器端对其进行解码

https://docs.microsoft.com/en-us/dotnet/api/system.net.webutility.urldecode?view=net-5.0 it it gives You issues, https://docs.microsoft.com/en-us/dotnet/api/system.net.webutility.urldecode?view=net-5.0它给你带来了问题,

When it comes to the problem you describe, it looks like you have to look at your routes, your request doesn't end where you want it to i suspect.当谈到您描述的问题时,看起来您必须查看您的路线,您的请求并没有在我怀疑的地方结束。 One thing you could try is to remove the Authorize attribute from the controller and then see if you even hit the right controller, which you probably do not.您可以尝试的一件事是从控制器中删除 Authorize 属性,然后查看您是否点击了正确的控制器,而您可能没有点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM