15 April, 2022

Get Local or Remote Logon User Using Request.LogonUserIdentity.Name

Using Environment.UserName returned server name, then application pool name. That is what I encountered recently. And since I needed to know who is using that small web app, as it is logged into an Oracle table, I had to find out how to get this info correctly.

Searching the web usually and always gives a lot of answers. And you have to fish out what may work. But apparently, I had to really search for longer.

My goal is to get the logged-on user from a laptop, as well as the PC name. And aside from the failure of returning the server name, the application pool name, and even the IIS IUSR at one time, that is not what I wanted. It had to be the logged-on user, and also the machine used (Environment.MachineName).

Fortunately, I managed to piece together and make do 3 points:

1. In the server, you have to disable the Web Site's Anonymous Authentication setting.

2. Then, to get the logged-on user, use Request.LogonUserIdentity.Name.

3. Finally, get PC or computer name using System.Net.Dns.GetHostEntry(Request.ServerVariables("remote_addr")).HostName

1. Disable the Web Site's Anonymous Authentication Setting

In the server where your web application is published or deployed, select and double-click on your website. In the IIS section, double-click on Authentication. Right-click on Anonymous Authentication and select Disable if it is Enabled. Step one is done.

2. Capture Local UserName

Below is the code sample, where I employed redundancy. This will work only when step 1 is done.

Dim userName As String = Environment.UserName

Dim pcUser As String = Request.LogonUserIdentity.Name

If (pcUser.Trim.Length > 0) Then

userName = pcUser

End If

3. Capture Local Computer Name

Finally, use the below code to get the local PC or computer name. Again, this is employing redundancy.

Dim pcName As String = Environment.MachineName

Dim comp_name() As String = System.Net.Dns.GetHostEntry(Request.ServerVariables("remote_addr")).HostName.Split(New Char() {"."c})

pcName = comp_name(0).ToString()

There you go! 3 steps to capture the local user and local computer name. Nothing else, or if these steps don't work for you, then you need something else. Otherwise, you are all set. Hope this helps, how to get the local or remote logged-on user.

Till then!


16 March, 2022

Remove TFS Connection from Solution

How to remove TFS connection from solution? I was asking this question to myself. We are migrating from TFS to Tortoise, and it is taking some time for this to happen.

And meanwhile, whenever I am opening solutions to do edit on the source codes I have copied in my laptop, I get the notification: 


Team Foundation Server Version Control

The solution you are opening is bound to source control on the following Team Foundation Server: [TFS SERVER NAME]. Would you like to contact this server to try to enable source control integration?


I would click on No, do one with the code edit, debug, save, and done.

Or maybe not.

You see, the next time I open the source code, I am greeted with this question, and the source code won't load until I click on No. And again on the next edit, and so on and so forth.

So I searched the web for how to do this permanently.

Pretty quickly came one suggestion with 2 steps: 

1. Go to your solution's folder, search and destroy (read: delete) all files with *.vssscc and *.vspscc extensions.

2. Open your solution's .sln file in Notepad++ (or in a much more basic text editor such as Notepad) and remove the GlobalSection(TeamFoundationVersionControl) section.

Well, I'm in a hurry and most of the time I am even lazy to do these just 2 steps. And besides, this method requires some other steps not listed, but feel free to search for more info if you want to go this way.

Fortunately, I found another method that I can say is a one-time deal and it is done. Final.

Here's how it goes, 3 steps:

1. Open the solution, then when the prompt comes, click on No and make no mistake, click on No.

2. Once fully loaded, click on File, then Source Control, then Advanced, then Change Source Control.

3. You will be prompted with the following question, so affirmatively click on Yes.


---------------------------

Microsoft Visual Studio

---------------------------

Change Source Control - [MY_SOLUTION_NAME].sln

The current solution is associated with source control but is offline.

Would you like to completely disassociate the solution from source control?

---------------------------

Yes   No   Help   

---------------------------


How to remove TFS connection from a solution? 2 methods I have shown, with the 2nd method I have tried to be sure-fire. And that's how I am no longer bothered with the incessant "Would you like to contact this server to try to enable source control integration?" question.

If you are also bothered and you want it to stop, for good, try it. I did, and I am very much contented and now happily coding.

Till then!