如何判断ASP.NET模拟是否有效?

时间:2011-05-12 21:36:55

标签: asp.net-mvc-3 iis-7.5 impersonation

使用ASP.NET模拟,可以使用Environment.UserName来确定模拟是否有效?如果网站正确模拟,Environment.UserName是否应该返回我的用户名?

1 个答案:

答案 0 :(得分:2)

您应该使用User.Identity.Name

[Authorize]
public ActionResult Foo()
{
    // If we got so far it means that the user is authorized to 
    // execute this action according to our configuration => 
    // we can work with his username
    string username = User.Identity.Name;
    ...
}