【发布时间】:2015-12-30 03:21:39
【问题描述】:
尝试搜索互联网以找到解决方案,但现在几天都没有运气。我正在尝试使用 web api 实现忘记密码功能,但是在将重置电子邮件链接发送给用户后,我遇到了回调。
目前在我的控制器中我有
var callbackUrl = new Uri(Url.Link("ResetPasswordRoute", new { userId = cUser.Id, code = code }));
此回调将发送到用户的电子邮件。我希望用户单击此链接并为他打开一个重置页面,该页面还传递用户 ID 和代码。因此,输入新密码的视图。一旦他们提交,我希望它会进入我的 httpGet resetPassword 方法,代码、用户 ID 和新密码如下所示。
[HttpGet]
[Route("ResetPassword", Name = "ResetPassword")]
public async Task<IHttpActionResult> ResetPassword(string userId = "", string code = "")
{
if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(code))
{
ModelState.AddModelError("", "User Id and Code are required");
return BadRequest(ModelState);
}
IdentityResult result = await _repo.ResetPasswordRoute(userId,code);
if (result.Succeeded)
{
return Ok();
}
else
{
return GetErrorResult(result);
}
}
所以问题是我真的很困惑我如何设置 ResetPasswordRoute 以在单击链接时在 webapi 中推送视图。以及 angularjs 如何捕获参数,因为 url 是一个阴影 url,因为它需要另一个路由页面。
我已经创建了一条路线:
}).when("/pages/reset", {
templateUrl: "app/views/pages/reset-password.html"
我意识到我不能真正使用 $routeparameters。我已经阅读了大多数指南,但所有指南都是针对 MVC 的,它具有基于字符串代码的返回 View()!= null 并且 webapi 不使用 View()。任何帮助将不胜感激。
【问题讨论】:
标签: asp.net angularjs url asp.net-web-api angularjs-routing