【发布时间】:2015-11-14 20:39:49
【问题描述】:
我有网络 api 帐户控制器,我在其中确认用户电子邮件
[System.Web.Http.AllowAnonymous]
[System.Web.Http.HttpGet]
[System.Web.Http.Route("ConfirmEmail", Name = "ConfirmEmailRoute")]
public async Task<IHttpActionResult> ConfirmEmail(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 this.AppUserManager.ConfirmEmailAsync(userId, code);
if (result.Succeeded)
{
return Ok();
}
else
{
return GetErrorResult(result);
}
}
}
当用户单击电子邮件中的确认链接时调用此方法。之后我想将其重定向到“ConfirmidSuccessfully”页面
在 MVC 中我们可以这样做:
return View("ConfirmidSuccessfully");
还有其他重定向方式,例如:
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri("/ConfirmidSuccessfully");
return response;
其实有2个问题: 根据WEB API从web api方法重定向是否好,或者有更好的方法 最合适的方法是什么
【问题讨论】:
标签: asp.net-mvc asp.net-web-api2