How to get windows logged on os user name?

Hi,

 In my old ASP.NET 1.1. code I have follwoing code in Page_Load of a certain page to get the os username if windows authentification checkbox is on in IIS 5.1

        Session("OSUsername") = Request.ServerVariables("REMOTE_USER")
        Response.Redirect("subfolder2/subsubfolder3/TheSite.aspx")

 Now I have migrated the code to ASP.NET 2.0 and the Server Variable REMOTE_USER is empty, although windows authentification checkbox is on !!!

 How can I get OS username in ASP.NET 2.0?

Background of the code above: Normally there is a logon page to identify the user, but because it is an intranet application our customer do not want to logon,
so I catch the os username, save it in the sessions variable, and check the user rights against a database in the redirected page, so for the user it is one call,
but in background the os user name is taken for identification.

 Many thanks for your answer in advance!

0
JohnSheridan
7/5/2007 8:22:40 AM
asp.net.security 27051 articles. 1 followers. Follow

4 Replies
922 Views

Similar Articles

[PageSpeed] 36

Hi there,

Try using User.Identity.Name to get the windows username. Since you have windows authentication enabled from IIS, you should be able to get the username.  I am not too sure about "Remote_User" property available on HTTP.

 However, if you are trying to obtain the username on Global.asax, then use Context.User.Identity.Name. 

Hope this helps,

rgds,

0
suhash
7/5/2007 11:18:37 AM

Did you try Request.ServerVariables("LOGON_USER")  as well?

I'd also make sure double check that anonymous access is denied for the resource you are trying to access, as none of the user identity variables will be populated until the user is forced to authenticates to access a protected resource.

0
dvallone
7/5/2007 3:51:03 PM

As suhash mentioned User.Identity.Name is what you would most likely use now but just for reference..

Session("OSUsername") = Request.ServerVariables("REMOTE_USER")
in .NET is now
Session["OSUsername"] = HttpRequest.ServerVariables["REMOTE_USER"];
The above code is in C# (cause that's what I know). 
See MSDN:
http://msdn2.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx

I <3 AJAX
0
GRiM
7/5/2007 4:00:02 PM

Hi

What's your IIS authentication setting? When you enable Anonymous authentication in conjunction with Windows authentication or if you grant access to the Anonymous user in the <authorization> section while you are using any authentication mode other than None, other server variables such as AUTH_USER and REMOTE_USER (as well as the HttpContext.Current.User.Identity.Name property) also return an empty string.


Best Regards
XiaoYong Dai
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
XiaoYong
7/10/2007 2:31:57 AM
Reply:

Similar Artilces:

How to get windows log-in user name using vb.net code?
Hi, I built an asp.net web application on our companies HR system so that recruitors can post jobs. Is there a way to get the windows logged in user name using vb.net code? This user name is using for tracking who posted the job. Thank you.   Windows Authentication provides some options, as does forms authentication.  See if you get what you need through User.Identity.Name.  Take a look at: http://www.15seconds.com/issue/020220.htmhttp://aspnet.4guysfromrolla.com/articles/120705-1.aspx JeffPlease: Don't forget to click "Mark as Answer" on the p...

Getting first name and last name from Windows logged in user
 I'm sure there must be an easy way of getting the actual first name and last name from an Windows domain\username via the Windows Identity or Principal object, but I can't seem to figure it out. Does anyone have any examples of this? try this: HttpContext.Current.User.Identity.Name  Thanks - tried that...it returns nothing or domain\loginName :( Please check that on the site properties window (in IIS Admin console), in the security tab, click on the modify or edit button in the authentication and anonymous access group and make sure only the "Windows Inte...

Get Windows logged in user name
Hi,I have my own custom security module in my web application. I would like to implement signle sign on to my application. I was thinking to use mapping approach, which retrieve logged in window user name and "auto login" for him, retrieve his coressponding permission and etc.How could I retrieve windows logged in user name? Thank you     you can get the currently logged in user identity by using: WindowsIdentity ident = System.Security.Principal.WindowsIdentity.GetCurrent(); Now you can get the prinipals properties and groups and other useful stuff like th...

Problem in getting logged in user Name for ASPX page with (even with this.User.Identity.Name)
Hi  friends,  I am creating an application that takes current logged in user and displays on the page itself. for this I am getting the user name in PageLoad function by using this.User.Identity.Name and then storing the value in a hidden variable for aspx page. I am using this hidden  variable to display the name of the user. I am using Windows authentication for this. Now problem that I am getting is that when multiple user launch the application from different machine and if they click simultaneously, name of one user appears on the paged displayed on the machine of ot...

How do I get the logged in user's name with windows authentication?
I have windows authentication turned on at the web server level so that it prompts for a password when the site is accessed. How do I get the username that is currently logged in? I tried using User.Identity.Name but It's just returning an empty string....

Getting the user name of the currently logged in user
I'm writing my first custom module. Just as an experimental project I would just display information about the currently logged in user. I can get the User Id, but I don't know where to get the rest of the information. How do I get this? Hi, Just create a new UserController to get the information about one user via the method GetUser(PortalId, UserId) and store it into a UserInfo. Then you can get the rest of the information from this UserInfo [VB] Dim myUser As New UserInfo Dim myUserController As New UserController myUser = myUserController.GetUser(PortalId, Use...

Application User and still getting the logged in User Name
Hi I have a very intranet situation where User opens the Web Page Now here is calls a Database table where User Rights are stored But access to this database table is given to dbo and Application Uer which is created in IIS Server folder by clicking on Allow Anomymous Login=true when I try to run the Table Query and pass the USer Name I get null UserName how to deal with this situation   Thanks       so do you have anonymous access ON? try deny anonymous access to your application. Enable impersonation in your web.config./GuruBhai Hi, By default, ASP.N...

WINDOWS AUTHENTICATION
Hello ,I am Using windows authentication in my asp.net application. I want to know a way to get the Windows users , Group name who is logged in to my application .I mean I want to know user's group name so that role can be implimented for that group user in my asp.net application.  Thanks & Regards.Harish Patel.If you are not sure better ASK.. Because wrong guesses are COSTLY.. !!  --Harish Patel www.MicrosoftSQLandASP.netpatelharish@gmail.com I Tried with the Method Below but it does not work and give error as mentioned below : Dim test As Booleantest = User.IsInRole("G...

How to get an user name of windows when user access to web site internal
hi all, My web site used internal. I host a web site on server, How to get user name of machine that logoned and  access to this web site ? my application write in ASP.net 2.0, run on IIS 6.0I have used command below but cannot get Request.ServerVariables("LOGON_USER") thanks Here's an article that might help you. In short, you need to configure your application in IIS to use "Integrated Windows Authentication" (instead of Anonymous access) and set the authentication mode in your web.config file to Windows. Once this is done you can access ...

Getting the user name when log-in.
Hi, when a user is created i have added a step that asks him to insert his name. I want to keep it in the Profile object but when i try to write it there in the CreatedUser event i get an exception telling me that unauthenticated users have no access to the Profile object. How can this be solved? Is there another way to obtain the user name and use it during the sessoin when ever this user logs in? Thanks!  Be happy. the profile of the user is not available in the CreatedUser event vai the 'Profile' object. this may help: http://p2p.wrox.com/topic.asp?TOPIC_ID=41084http:...

getting logged in user name
I have a login page with a login control.I am storing my credentials in web.config file.How do i get the logged in user name on my page?Here is what I have: protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { if (FormsAuthentication.Authenticate(Login1.UserName, Login1.Password)) { FormsAuthentication.RedirectFromLoginPage(Login1.UserName,Login1.DisplayRememberMe); Response.Redirect("Home.aspx"); } } Web.config: "Forms"> "appNameAuth" path="/" login...

Get the name of user logged in
Hi Suppose i have logged into the system with my username and pwd . Iam developing a web appli in which i have get the name of the user who is currently logged into the system. How to do it????   Thanks I all depends on what kind of Auentication mode you are using. If you are using "forms" authentication you have to desing your own form to accept login credentials which you can store in Session variable and make use of it whereever required. it also gets stored in a cookie. In case of "windows" authentication, please visit these links http://msdn.microsoft....

get windows user name
Can anyone tell me how to pull the logged on windows username via javascript? Thanks, Steve    this is not possible in javascript but you can do it using .Net by calling the following method Request.ServerVariables("LOGON_USER") It will return a string containing the windows username. However it will only work if IIS is setup to use windows logins and you are running the ASP.Net site on an intranet and not on the internet. Please Remember to click "Mark as Answer" on this post if it helped you. -------------------http://www.crazycoder.co.ukG...

How do I get the name of the user logged in on the client
I'm working on an intranet app. I need to get the username on the client in order to display personal stuff. How do I do this?? David LeggDave Legg NOTE: The Intranet app is hosted on the same computer as that is the only computer. David LeggDave Legg Check the server variables connected to the request object. One of them (I think USERNAME or something - look it up) has the name of the logged on user. WHEN the IIS is configured in such a way that it actually retrieves the user's name.Thomas TomiczekPowerNodes ApS(Microsoft MVP C#/.NET)---Building a Website? Try the PowerNodes CM...

Web resources about - How to get windows logged on os user name? - asp.net.security

Window - Wikipedia, the free encyclopedia
This article is about the part of a building. For the Microsoft operating system, see Microsoft Windows . For other uses, see Window (disambiguation) ...

Microsoft Windows Information, Solutions, Tools - Windows IT Pro
Microsoft Windows information and solutions for IT pros. Topics include cloud computing, Windows Server, Exchange, Outlook, PowerShell, virtualization, ...

The Windows Blog
The Windows Blog is Microsoft's Official Blog for the Windows Operating System.

Best Windows apps this week
One-hundred and fifty-six in a series. Welcome to this week's overview of the best apps and games released for Windows 8.x and Windows 10 in ...

Woman, 80, breaks window to try to free husband from fire
Texas woman focused on saving husband after escaping from house on fire

CNET UK podcast 459: The right way to watch Star Wars, Bezos' rocket and your thoughts on Windows Phone ...
Google's Star Trek-style wearable, a historic rocket and whether we need "The Phantom Menace" are all up for debate on the latest episode of ...

Microsoft acknowledges bug led to Windows 10 November upgrade stoppage
Microsoft has restored access to Windows 10's November upgrade from its download center, saying that it pulled the upgrade because of a bug. ...

Sony confirms official PS4 Remote Play app for Windows and Mac
Well that was quick. It's only been a couple of days since someone came up with an unofficial app to stream PlayStation 4 gaming to PC, but earlier ...

Turkish Consulate in Moscow Was Stoned and Had Bottles Thown Through It’ Windows
Over five hundred people gathered at Turkish embassy in Moscow to protest and throw stones, bottles, paint cans and even eggs into the building ...

Windows 10’s broken fall update removes user-installed applications without asking first
Microsoft's latest Windows 10 update is causing problems for at least some users, and uninstalling programs without the user's consent or evidence ...

Resources last updated: 11/28/2015 2:55:58 AM