How to get the Current windows username?

From Dotnetspider

I am trying to integrate single - sign - on Facility for one application in .NET.
I would like get the cuurent windows user name so that i will compare that name with the name in DB. If succeeds application should allow user further. Please help

Answers .............




20 Sep 06 03:28 AM : Padma : MNC
Dim strLogonUser as string
strLogonUser = Request.ServerVariables("REMOTE_USER")


20 Sep 06 03:34 AM : chandan nagaraj :
Dim temp As String = System.Web.HttpContext.Current.User.Identity.Name
dim Username as string
Username = Mid(temp, InStr(temp, "\") + 1)


20 Sep 06 03:54 AM : Gaurav Sharma : MCAD/MCP
http://www.dotnetlearner.blogspot.com
to access Current window User name u need to read it from Registry
thanks


20 Sep 06 04:56 AM : kumar : WC2
Hi,

you can write like below

HttpContext.Current.User.Identity.Name

thanks and regards,
kumar


20 Sep 06 05:03 AM : chandan nagaraj :
using three ways we can get the User Name using C#

1) System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

string strName = p.Identity.Name;

[ OR ]

2) string strName = HttpContext.Current.User.Identity.Name.ToString();

[ OR ]

3) string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name

string strName = Request.ServerVariables[5]; //Finding with index

In Above 3 Cases returnin string contains DomainName\WinNTLoggedUserName

Using string operations seperate the DomainName and UserName.

Source:-Code Project


25 Apr 07 04:50 AM : vivek singh bhadauriya : ANPL
http://www.agroecommerce.net.in

In window application (VB.Net)use this
on login form...
SaveSetting("AnyName", "Properties", "UserID",txtName.text)

Now on any form u can get that value by....
Dim UserId As string = GetSetting("AnyName", "Properties", "UserID")

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

From TheScript

To get the current user, better switch to .NET:
Environment.UserName
or
System.Windows.Forms.SystemInformation.UserName
--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/

-------------------------------------------------
Hi,
You can use :
WindowsIdentity.GetCurrent().Name
It return the user logged on the system.
Hope this help,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

1 nhận xét:

Kale Co Jakim on December 11, 2017 at 10:01 PM said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

 

Coding experience share Copyright © 2010 | Designed by Ipietoon for Free Blogger Template