HttpContext.Current.User.Identity.IsAuthenticated和 和有this.User.Identity.IsAuthenticated什么区别?有时它们出现在我的代码中,有时它们没有(所以我必须使用另一个)。它们的意思是一样的还是应该有一种特定的“上下文”让我使用它们?
我有我在其中一个课程中使用的代码:
if (!HttpContext.Current.User.Identity.IsAuthenticated) {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
那么什么是this和HttpContext?我知道this指的是一个特定的实例,但是HttpContext呢?
HttpContext.Current.User.Identity.IsAuthenticated并且this.User.Identity.IsUthenticated是相同的东西,但用法不同。
您
this.User.Identity.IsUthenticated在控制器内部使用,但如果您在控制器外部并且您需要知道用户是否经过身份验证,您使用HttpContext.Current.User.Identity.IsAuthenticated.
| 归档时间: |
|
| 查看次数: |
1171 次 |
| 最近记录: |