asp.net mvc4中的oauth重定向
本文关键字:oauth 重定向 中的 mvc4 net asp | 更新日期: 2023-09-27 17:58:40
我将尝试在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
有人知道我该怎么做吗?
试试这个:
[HttpGet]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider) {
return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback"));
}
通过使用RedirectToAction
,您正在对操作的url发出GET请求,您需要在AccountController
上的ExternalLogin
操作中接受HttpGet
[HttpGet, HttpPost]
在AccountController上的ExternalLogin操作中接受HttpGet,其他成员也表示。