public class HomeController : BaseController
{
public bool IsAuthenticated
{
get
{
return this.HttpContext.User != null &&
this.HttpContext.User.Identity != null &&
this.HttpContext.User.Identity.IsAuthenticated;
}
}
为什么我不能在同一个类的方法中执行此操作?
public ActionResult Index()
{
if(IsAuthenticated)
{...do something...}
}
为:
The name 'IsAuthenticated' does not exist in the current context
实例化类以创建对其“IsAuthenticated”自动实现属性的引用是没有意义的,因为我调用ActionResult Index方法时触发了类默认构造函数(即使它不需要显式声明)。 / p>
...困惑