2015-12-07 34 views
1

我的api及其帳戶管理問題很少。無論何時用戶創建新帳戶,都必須通過點擊通過電子郵件發送的鏈接進行確認。這很好。 但是,當用戶點擊鏈接時,它會打開一個空白的瀏覽器窗口。現在我想將用戶重定向到提供應用程序說明的網頁。經過一番研究,我發現了「重定向(string url)」命令。重定向到網頁C#API

[HttpGet] 
[AllowAnonymous] 
[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) 
    { 
     Redirect("http://www.orf.at"); 
     return Ok(); 
    } 
    else 
    { 
     return GetErrorResult(result); 
    } 
} 

該地址應該只是一個例子。但是,只要點擊鏈接,瀏覽器仍會打開一個空白標籤。有沒有可能避免這種情況?最好的解決方案是將用戶重定向到另一個站點。但是,如果這不起作用,可以以某種方式防止打開新窗口?

回答

2

,而不是返回Ok()Redirect("http://www.orf.at");

if (result.Succeeded) 
{ 
    return Redirect("http://www.orf.at"); 
} 
else 
{ 
    return GetErrorResult(result); 
} 
+0

沒錯的,它的工作原理!謝謝 :) –