MVC5 Web 应用程序脚手架 - Account/Logoff - 为什么使用 HTTP Post?

MVC5 Web Application Scaffold - Account/Logoff - Why use HTTP Post?

我正在尝试了解 MVC 5 Web 应用程序模板,我注意到特别注意注销 link 周围的安全性。

在脚手架模板中,_LoginPartial.cshtml 视图中的 "LogOff" link 位于带有 AntiForgeryToken 的 HTML 表单内,并被定义为 JS 调用表单的提交操作,如下所示:

@if (Request.IsAuthenticated)
{
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
    @Html.AntiForgeryToken()

    <ul class="nav navbar-nav navbar-right">
        <li>
            @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
        </li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
    </ul>
    }
}

ActionController 中相应的动作方法 Account/LogOff 定义如下:

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            AuthenticationManager.SignOut();
            return RedirectToAction("Index", "Home");
        }

我的问题是 - 背后的原因是什么?为什么注销动作需要如此多的安全保护?为什么不把这个放在视图中,

@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
@Html.ActionLink("Log Off", "LogOff", "Account", routeValues: null, htmlAttributes: new { title = "LogOff" })

控制器中的这个:

 public ActionResult LogOff()
        {
            AuthenticationManager.SignOut();
            return RedirectToAction("Index", "Home");
        }

这会造成什么安全漏洞?

谢谢。

请参考这个link:Logout: GET or POST?

它将回答您关于为什么要在注销中使用 Post 的问题。