System.Web.HttpContext.Current.User.Identity.Name VS System.Environment.UserName在ASP.NET [英] System.Web.HttpContext.Current.User.Identity.Name Vs System.Environment.UserName in ASP.NET

查看:138
本文介绍了System.Web.HttpContext.Current.User.Identity.Name VS System.Environment.UserName在ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 System.Web.HttpContext.Current.User.Identity.Name System.Environment.UserName 在ASP.Net Web应用程序项目的背景下?

What is the difference between System.Web.HttpContext.Current.User.Identity.Name and System.Environment.UserName in the context of a ASP.Net Web Application Project?

这里是我想要做code:

Here's the code of what I'm trying to do:

Database myDB = DatabaseFactory.CreateDatabase();
bool IsAuthUser = myDB.ExecuteScalar("procIsAuthorizedUser", System.Environment.UserName);

如果它们在功能上是相同的,这是在性能方面更好?

If they are functionally identical, which is better in terms of performance?

这是一个C#4.0 / ASP.Net Web应用程序将在内部组织看使用率适中。谢谢你的答案。

This is a C# 4.0/ASP.Net web application which will see moderate usage internally in the organization. Thank you for the answers.

推荐答案

System.Environment.UserName 返回身份下承载您的Web应用程序的应用程序池正在运行。如果你正在使用Windows身份验证和模拟那么这将是实际的用户名,但在任何情况下你还是使用的HTTP上下文提供的信息更好。没有性能上打两种方式。

System.Environment.UserName returns the identity under which the app pool that hosts your web app is running. If you're using Windows authentication and impersonation then it will be the actual user's name, however in all cases you're better off using the information provided by the HTTP context. There is no performance hit either way.

这篇关于System.Web.HttpContext.Current.User.Identity.Name VS System.Environment.UserName在ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆