【发布时间】:2013-09-30 06:34:17
【问题描述】:
我见过以下两个可访问的布尔值:
System.Web.Mvc.Controller.User.Identity.IsAuthenticatedSystem.Web.Mvc.Controller.Request.IsAuthenticated
这些有区别吗?他们似乎都做同样的事情,所以我不确定该使用哪个。
我想做的是:
@if (User.Identity.IsAuthenticated) {
if (User.IsInRole("Admin")) {
@Html.ActionLink("Admin", "AdminController")
}
}
或
@if (Request.IsAuthenticated) {
if (User.IsInRole("Admin")) {
@Html.ActionLink("Admin", "AdminController")
}
}
以上两种方法都一样好吗?
【问题讨论】:
标签: c# asp.net-mvc authentication principal