[英]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.