【问题标题】:Email Verification URL in ASP.NET WEB APIASP.NET WEB API 中的电子邮件验证 URL
【发布时间】:2026-01-19 01:25:01
【问题描述】:

如何在 ASP.NET WEB API 中使用给定的 URL 进行电子邮件修改?

var Email="test@test.com" var key="122";

"http://localhost:50740/api/Users/VerifyEmail/" + Email + "/" + key

当我进入网络浏览器时,调试它

[HttpGet]
public HttpResponseMessage VerifyEmail(string email, string verificationKey)
{
}
   paramters of action method are always null.

在 Global.asax.cs 中我定义了以下路线

routes.MapHttpRoute(
                name: "EmailVerification",
                routeTemplate: "api/{controller}/{action}/{email}/{verificationKey}",
                defaults: new { action = "VerifyEmail", email = "", verificationKey = "" }
             );  

基本上,我希望处理验证电子邮件,其中包含两个参数电子邮件和密钥。

我们将不胜感激。

【问题讨论】:

  • 我完全使用了你的代码,对我来说效果很好。是否有一条更贪婪的路线覆盖了您在上面映射的路线?

标签: rest restful-authentication asp.net-mvc-4 asp.net-web-api


【解决方案1】:

我通过将自定义路由移到定义路由的顶部找到了解决方案。

【讨论】: