简体   繁体   English

ASP.NET Core 2.2 Web API 项目:使用端点实现电子邮件确认回调 url

[英]ASP.NET Core 2.2 Web API project: implement email confirmation callback url using endpoint

I am trying to do something a little different to the examples provided by Microsoft (docs) with regards to generating a confirmation token and then sending out a confirmation email link to the user.我正在尝试做一些与 Microsoft (docs) 提供的示例略有不同的关于生成确认令牌然后向用户发送确认电子邮件链接的事情。

Currently I have a few steps in an CreateUserAsync controller method that creates a user, if successful generates an email confirmation token (using the GenerateEmailConfirmationTokenAsync method) - all is well to this point a seemingly valid token is generated.目前,我在创建用户的 CreateUserAsync 控制器方法中有几个步骤,如果成功生成电子邮件确认令牌(使用 GenerateEmailConfirmationTokenAsync 方法) - 到目前为止一切都很好,生成了一个看似有效的令牌。

Then next step is to generate a confirmation email link (using properties like Request.Scheme, Request.Host etc) which is emailed to the user using SendGrid (configured as per the Microsoft documentation) - again this step works great I am able to see a test email appear in an test Gmail account.然后下一步是生成一个确认电子邮件链接(使用 Request.Scheme、Request.Host 等属性),该链接使用 SendGrid(根据 Microsoft 文档配置)通过电子邮件发送给用户 - 这一步再次奏效,我能够看到测试电子邮件出现在测试 Gmail 帐户中。

The problem seems to be the code (Token) that is generated - I tried using WebUtility's UrlEncode method but this does nothing to the token it remains the same and when I tried to test the URL I got a message:问题似乎是生成的代码(令牌) - 我尝试使用 WebUtility 的 UrlEncode 方法,但这对令牌没有任何影响,它保持不变,当我尝试测试 URL 时,我收到一条消息:

The request filtering module is configured to deny a request that contains a double escape sequence请求过滤模块用于拒绝包含双转义序列的请求

Any suggestions how I could implement the above in a Web API project (as apposed to the example on the Microsoft Doc site: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-2.2&tabs=visual-studio ).关于如何在 Web API 项目中实现上述内容的任何建议(与 Microsoft Doc 站点上的示例相关: https : //docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view =aspnetcore-2.2&tabs=visual-studio )。

I resolved this by changing the POST to a GET and using the [FromQuery] attribute to enable me to generate a more traditional query string parameter style URL which provides the necessary query string parameter values.我通过将 POST 更改为 GET 并使用 [FromQuery] 属性使我能够生成更传统的查询字符串参数样式 URL 来解决此问题,该 URL 提供必要的查询字符串参数值。

I had to also ensure I was encoding the email confirmation token when I was creating the confirmation URL using WebUtility.EncodeUrl method but I found with ASP.NET Core my controller method (that has the [FromQuery] attribute) was decoding the incoming string so I didn't need to decode on arrival - but this could be a feature in the latest version of ASP.NET Core 2.2 that I am using.我还必须确保在使用 WebUtility.EncodeUrl 方法创建确认 URL 时对电子邮件确认令牌进行编码,但我发现使用 ASP.NET Core 我的控制器方法(具有 [FromQuery] 属性)正在解码传入的字符串,因此我不需要在到达时解码 - 但这可能是我正在使用的最新版本的 ASP.NET Core 2.2 中的一个功能。

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

相关问题 ASP.NET Core Identity email React 路由确认 URL - ASP.NET Core Identity email confirmation URL for React routes 在 ASP.NET 核心 Web Z72664DC0959F3B0C0470479 中注册后,将 email 确认令牌作为可点击链接发送给用户 - Send email confirmation token as clickable link to user upon registration in ASP.NET Core Web Api 使用 ASP.NET Core 2.2 Web API 项目中的实体框架类库时抛出异常 - Exception thrown when using Entity Framework class library from ASP.NET Core 2.2 Web API project 使用 ASP.NET 内核 6.0 Web ZDB974238714CA8DE634A7CE1D08 发送 email - Sending email using ASP.NET Core 6.0 Web API ASP.NET 核心 Web API。使用 NSwag 生成的客户端未命中 PUT 端点 - ASP.NET Core Web API. The PUT endpoint is not getting hit using NSwag generated client 在 asp.net core api 中创建回调 url - create callback url in asp.net core api 路由 URL 中的电子邮件地址在 Asp.Net Core Web Api 中给出 403 错误 - Email Address in Route URL giving 403 error in Asp.Net Core Web Api ASP.NET Core 2.2中的端点路由不起作用 - Endpoint Routing in ASP.NET Core 2.2 is Not Working Asp.NET 核心 2.2:Swagger 端点特定安全定义 - Asp.NET Core 2.2: Swagger endpoint specific security definition 如何在ASP.NET Core Web API中实现通过id获取? - How to implement get by id in ASP.NET Core Web API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM