使用ASP.NET模拟,可以使用Environment.UserName
来确定模拟是否有效?如果网站正确模拟,Environment.UserName
是否应该返回我的用户名?
答案 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;
...
}