2014-04-17 67 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其他成员也表示。