创建一个 link 以从 Web API 重定向到网站 Controller ActionResult

Create a link to redirect to the Web site Controller ActionResult from Web API

我需要向用户发送电子邮件以重置密码。其中包含 link 以打开网站中的密码重置页面。 网站和网络 api 都在相同的 domain.But 不同的解决方案中。

我在网络 api 中创建了一个 link。

var callbackUrl = Url.Link("ResetPassword", new { Controller = "Account", code = token });

但是当它在 postman 上测试时它显示 'ResetPassword' 在路由集合中找不到。 网站的Account controller中有ResetPassword ActionResult。

[AllowAnonymous]
[Route(Name="ResetPassword")]
public ActionResult ResetPassword(string code)
{
     return code == null ? View("Error") : View();
}

RegisterRoutes方法是,

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

我还没有部署解决方案。 它会在部署时起作用吗?

你基本上错放了 路线名称 动作名称 。请尝试使用这个:

var callbackUrl = Url.Link("Default", new { Controller = "Account", Action ="ResetPassword", code = token });