ApiController中的Url.Route不包含主机名

Hei*_*ich 1 .net c# asp.net-mvc asp.net-web-api

ApiController,我正在生成一个通过电子邮件发送给用户的密码重置链接.一切正常,但Url.Route函数不会生成与主机名的链接.我不确定是不是因为我正在使用localhost它导致问题.

这是生成链接的代码

string callbackUrl  = Url.Route("DefaultApi", new { controller = "Account", action= "ResetPassword", UserId = user.Id, code = code });
Run Code Online (Sandbox Code Playgroud)

这是生成的链接

https:///api/Account/ResetPassword?UserId=aaaaaaaaaa&code=aaaaaaaaa
Run Code Online (Sandbox Code Playgroud)

注意https:///api,它应该包括主机名和端口之类的https://localhost:4040/api.为什么不包含主机名?

And*_*rei 6

Url.Route仅生成相对URL.要获得绝对网址,请使用Url.Link:

string callbackUrl  = Url.Link("DefaultApi", new { controller = "Account", action= "ResetPassword", UserId = user.Id, code = code });
Run Code Online (Sandbox Code Playgroud)