2014-04-17 95 views
0

我會盡力實現在asp.net mvc4項目,OAuth授權重定向OAuth的重定向

控制器

public ActionResult SomeName() { 
      if (!User.Identity.IsAuthenticated) { 
       return RedirectToAction("ExternalLogin", "Account", new { provider = "vkontakte" }); 
      } 
} 

賬號

 [HttpPost] 
     [AllowAnonymous] 
     [ValidateAntiForgeryToken] 
     public ActionResult ExternalLogin(string provider) { 
      return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback")); 
     } 

錯誤

The resource cannot be found. 

Description: HTTP 404. The resource you are looking for (or one of its 
dependencies) could have been removed, had its name changed, or is temporarily 
unavailable. 
Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /Account/ExternalLogin 

有人知道我該怎麼辦嗎?

回答

0

試試這個:

[HttpGet] 
    [AllowAnonymous] 
    [ValidateAntiForgeryToken] 
    public ActionResult ExternalLogin(string provider) { 
     return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback")); 
    } 
0

使用RedirectToAction你是一個GET請求,你行動的網址,你需要在你的AccountController

0

RedirectToAction ExternalLogin行動接受HttpGet是302重定向請求這本質上是GET。如果你應該利用從查看您的行動,以及,你可以使用這兩個動詞:

[HttpGet, HttpPost] 
0

在ExternalLogin您的AccountController行動接受HTTPGET其他成員也表示。