C# User.Identity.Name-哪个程序集引用将其引入到项目中?

C# User.Identity.Name-哪个程序集引用将其引入到项目中?,c#,windows-authentication,visual-studio-2013,.net-assembly,asp.net-mvc-5,C#,Windows Authentication,Visual Studio 2013,.net Assembly,Asp.net Mvc 5,我无法找出User.Identity.Name来自哪个引用程序集。我怎么知道呢?我需要将它添加到类库中,而不是我制作的默认MVC5应用程序中,以便访问它 C#类库/AUser.cs public class AUser { public string Username { get { return User.Identity.Name // doesn't notice User } } } 似乎

我无法找出User.Identity.Name来自哪个引用程序集。我怎么知道呢?我需要将它添加到类库中,而不是我制作的默认MVC5应用程序中,以便访问它

C#类库/AUser.cs

public class AUser
{
    public string Username
    {
        get
        {
            return User.Identity.Name // doesn't notice User
        }
    }
}

似乎位于System.Web命名空间中

编辑

根据您的附加代码,您必须包含完全限定的名称,例如:

HttpContext.Current.User.Identity.Name

当您在控制器之外(或在另一个类中)时。请注意,如果在没有HttpContext的任何情况下使用这个MVC类之外的类,它将失败(带有NullReferenceException)。为了确保我们没有这些,我们通常要么传递HttpContext,要么传递我们需要的部分(用户名、Url等)作为函数参数。

@JamesT-让我看看是否可以找到其他任何东西,可能是子依赖程序集。你想怎么称呼它?调整了操作,希望如此helps@JamesT-随时!MvcController/View基类已经有一个对HttpContext.Current的引用,这就是为什么不需要在控制器或视图中指定所有这些。