Get windows authenticated user name in .net app? - asp.net

How to get windows authenticated user name in .net application? My app is hosted on IIS. There is no Login form. But, I want to get the windows user name of the persons browsing it. I tried all the request objects. principal object getcurrent().name returns IIS app pool user name. But not the actual user. Please help. Thanks.

You cannot. Unless your application is using windows auth (and they could be prompted at some point like in firefox) you cannot get this information. If you do allow it, then access it via http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx
HttpContext.User.Identity.Name
again though - they could be prompted for a login at some point.

You can't unless you enable windows authenication.

Related

What can cause incorrect user names when using IIS & Windows Authentication?

I'm currently experiencing an issue with some users of an ASP.NET 4.8 Web API application hosted on Windows Server 2012 and IIS. The following properties are not returning that user's correct user name, and instead returning the name of a service account used for this server:
HttpContext.Current.User.Identity.Name
HttpContext.Current.Request.LogonUserIdentity.Name
I have no idea how to begin troubleshooting this - myself and most other users do not experience this issue, but for a handful of users the above does not return the correct username, returning the username of a service account used to remotely connect to the server in question. Forcing a login via a browser private window does rectify the issue, and the application correctly returns the expected username for each of the above properties.
What could be a cause for Windows Authentication not returning the correct user name and what is the best way to troubleshoot an issue like this?
edit: I was able to resolve the issue, see my answer below
After some additional research and troubleshooting, I determined that the users experiencing the issue described above had the service account in question stored in the Windows Credential Manager:
Removing the service account in question allowed them to be authenticated with the Intranet site with their normal Windows domain\username. As #pcalkins suggested, at some point the affected users had used these credentials on their machine, and Chrome, Edge, IE were using that saved credential when authenticating with the Intranet site.
Please check the following steps:
Make sure that windows authentication is enable and Anonymous Authentication is disable for the website.
Enable integrated security in Interner Explorer (Options/Advanced and checkin the "Enable Integrated Windows Authentication" option).
Add your website to Local Intranet zone and select at least "Automatic logon only in Intranet Zone" option under Options/Security Settings/Local intranet/Custom level).
Aake sure the user and application server are in the same domain.

.Net Authentication and Authorization

I have one third party web application developed in the ASP.Net. This web application shows some pdf planning data which comes from the the oracle database.
I have windows authentication defined on this application for authentication purpose. So whenever i first launch this application there is a popup comes up and ask for username and password like this.
I want to get rid this pop up and Instead of entering different username and password each time I want to use a single userid/password for all the hits to this web application. Because I do not want all users to have access to my database.
Please help. I want to use the single username and password without getting the login popup.
Here is the solution i got for my problem We need do the things to get rid of the login popup
Set the IIS authentication mode as windows and Use the Active directory authentication.
Add the web site as a trusted website in the internet properties.
In the internet properties allow automatically login with username and password. It will use your windows username and password and login you.

Populationg LOGON_USER servervariable

I have a classic ASP Web application that's been running on a Windows Server 2003 server with IIS 6.0 for several years. I have to move it to a Windows Server 2008 server with IIS 7.0. I've got it working, but the ServerVariable LOGON_USER doesn’t get populated. This seems to be because I have enabled Anonymous Authentication and allowed Anonymous Authorization to the site. However, if I disable/deny either of those, then I get an Authentication or Authorization error when attempting to open it. I have to have the LOGON_USER variable for the program to work correctly, but no matter what combination of Authentication/Authorization I use, I get errored out if I don't allow anonymous login. Rather at a loss at this point as to what to try next. Any suggestions?
When you disable anonumous access, the site will become inaccessible for users that are not logged in.
You will need to add at least read-rights in Windows Explorer to the folder your web-application is running in.
If you do that, IIS will then prompt you for a username and password. You can use the credentials of the user you have assigned read rights to.
This will then authenticate you as that specific user, and allow you to run the site. This will also fill the LOGON_USER servervariable with the username of the user you added.
Here's some more documentation on how to create a user for access using basic authentication in IIS:
http://technet.microsoft.com/nl-nl/library/cc772009%28v=ws.10%29.aspx
http://msdn.microsoft.com/en-us/library/aa292114%28v=vs.71%29.aspx
How do I create a user account for basic authentication?

How to get current User Name in Silverlight application without asking user to login

I need to get current username of user who start silverlight application.
I was able to do it, when I get User.Identity.Name in aspx page and pass it to silverlight app.
But it requires windows authentication, so asks users to sign in with domain user(with same domain as iis server).
Is it possible to get windows username, without asking user to sign in, and get name even if user is in another domain?
It is not possible. You should use windows authentication within your service.

Is it possible to get the Windows logon name with site running asp.net forms authentication?

I have a website with a large user base configured with asp.net 2.0 forms authentication. Before the user logs in via forms authentication is it possible to retrieve the windows login name/user account name on the machine they are using?
Many thanks
It certainly is possible--by adding another web application to your system. Here's roughly how I have done it:
Your primary web app uses Forms authentication. On the forms login page, any user that is determined to be on the local LAN (check IP address), redirect them to another app that uses Windows authentication. In this second app, you can determine the user (assuming the browser is configured to send credentials automatically to the zone in which your app resides), then set a cookie which your first app can read, and redirect the user back to the original app.
This does work.
This would only be possible if you were using Windows Authentication in your web application and then only if the user had logged in.
The kind of information you are after is not sent as part of the web request (quite rightly) and is therefore unknown to the web server.
Unfortunately no - if the user has not logged on, they are browsing anonymously, and are therefore unknown to the server. There is no way to identify them.
Once they're logged on, if you're using impersonation use WindowsIdentity.GetCurrent().Name. However, for forms authentication there's no direct way to ask the browser for their Windows credentials as they may not even be running Windows!
Not BEFORE no (not from the server).
Depending on the type of Auth you use, though, and the way the site is configured, you CAN get them to log in with their windows details.
See Mixing Forms and Windows Security in ASP.NET on Microsoft's MSDN.
The main difference with #TheObjectGuy answer is that instead of using 2 websites, this does all in a single website by configuring IIS to use the Integrated Windows authentication just in a "single" page (WinLogin.aspx).

Resources