以下是忘记密码功能的Web API(与Android手机交互的Rest WebService)方法。
[HttpPost]
[AllowAnonymous]
[Route("ForgotPassword")]
public async Task<IHttpActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
//if (user == null ||!(await UserManager.IsEmailConfirmedAsync(user.Id)))
if (user == null)
{
return Ok();
}
var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Link("Default", new { Controller = "Account", Action = "ResetPassword", code = code });
/*await UserManager.SendEmailAsync(user.Id, "Reset Password",
"Please reset your password by clicking here : <a href=\""+ callbackUrl +"\">link</a>"); */
await UserManager.SendEmailAsync(user.Id, "Reset Password",$"{callbackUrl}");
return Ok();
}
return BadRequest(ModelState);
}
形成的CallbackURL是
http://localhost:[port number]/Account/ResetPassword?code=[code value] ...
但是我希望它指向另一个域(服务器)地址,而不是localhost地址。 我是否有可能使用URL.Link方法生成所需的URL?
答案 0 :(得分:0)
您可以使用状态301进行响应,您可以使用HttpStatusCode.Moved创建状态301。 301将生成对位置标头中指定的URI的get请求。 您可以阅读更多相关信息here
import concurrent.futures import ThreadPoolExecutor
import time
def expensive_operation():
time.sleep(20)
return 6
executor = ThreadPoolExecutor(1)
future = executor.submit(expensive_operation)
print(future.result())