【发布时间】:2015-08-05 11:52:48
【问题描述】:
我正在尝试了解 MVC 5 Web 应用程序模板,我注意到对 LogOff 链接周围的安全性给予了特别关注。
在脚手架模板中,_LoginPartial.cshtml 视图中的“LogOff”链接位于带有 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");
}
这会造成什么安全漏洞?
谢谢。
【问题讨论】:
标签: asp.net-mvc security asp.net-mvc-5 asp.net-identity