简体   繁体   中英

Deploying asp.net application in IIS6.0 with Forms authentication mode

I am getting user name by using the following code:

txtName.Text = Environment.UserName;

I have deployed the code in IIS and while running the application then i am getting user name as "NETWORK SERVICE" in the textbox instead of logged user name.

And I am using the FORMS authentication mode. (this is mandatory)

Thanks in advance

Forms Authentication means that you provide a form for your user, so that they can enter their credentials (that is, their username and password), and from now on, if they've entered their credentials correctly, you know who they are (through setting an authentication cookie on their browser, and doing many other things).

When you use Environment.UserName , what you do is to get the name of the user under who's privileges the current application is running. If you look at your Application Pool (AppDomain) in IIS6.0, then you should verify that your website is running as the Network Service user.

So, you have to use:

username.Text = HttpContext.Current.User.Identity.Name;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM