我将尝试在asp.net mvc4项目中使用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 :(得分:0)
试试这个:
[HttpGet]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider) {
return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback"));
}
答案 1 :(得分:0)
使用RedirectToAction
,您正在对您的操作的网址发出GET请求,您需要在HttpGet
ExternalLogin
行动时接受AccountController
答案 2 :(得分:0)
RedirectToAction是302重定向请求,本质上是GET。如果你也应该使用VIEW中的动作,你可以使用两个动词:
[HttpGet, HttpPost]
答案 3 :(得分:0)
在您的AccountController上的ExternalLogin操作中接受HttpGet,其他成员也说。