473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

System Username and Domain

Hi,

I need to get the windows current logged username and domain. Is it any
possibility?

1qa2ws
Nov 17 '05 #1
4 15929
If you are using WinForms or ASP.NET with Windows authentication:

WinForms:

System.Security.Principal.WindowsIdentity wi =
System.Security.Principal.WindowsIdentity.GetCurre nt();

ASP.NET:

System.Security.Principal.WindowsIdentity wi =
(System.Security.Principal.WindowsIdentity)HttpCon text.Current.User;
HTH,
~d

1qa2ws wrote:
Hi,

I need to get the windows current logged username and domain. Is it any
possibility?

1qa2ws

Nov 17 '05 #2
How it differs from System.Environment.UserName and
System.Environment.UserDomainName?

1qa2sw

"DotNet Coder" <d0*********@yahoo.dot.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
If you are using WinForms or ASP.NET with Windows authentication:

WinForms:

System.Security.Principal.WindowsIdentity wi =
System.Security.Principal.WindowsIdentity.GetCurre nt();

ASP.NET:

System.Security.Principal.WindowsIdentity wi =
(System.Security.Principal.WindowsIdentity)HttpCon text.Current.User;
HTH,
~d

1qa2ws wrote:
Hi,

I need to get the windows current logged username and domain. Is it any
possibility?

1qa2ws

Nov 17 '05 #3
Well, because, in the case of using ASP.NET, System.Environment.UserName
/System.Environment.UserDomainName will return the name of the currently
logged on user on the server. Not the client using your web application.

In winforms, I suppose you could use System.Environment with no problem.

HTH,
~d

1qa2ws wrote:
How it differs from System.Environment.UserName and
System.Environment.UserDomainName?

1qa2sw

"DotNet Coder" <d0*********@yahoo.dot.com> wrote in message
news:u6**************@TK2MSFTNGP09.phx.gbl...
If you are using WinForms or ASP.NET with Windows authentication:

WinForms:

System.Security.Principal.WindowsIdentity wi =
System.Security.Principal.WindowsIdentity.GetCur rent();

ASP.NET:

System.Security.Principal.WindowsIdentity wi =
(System.Security.Principal.WindowsIdentity)HttpC ontext.Current.User;
HTH,
~d

1qa2ws wrote:
Hi,

I need to get the windows current logged username and domain. Is it any
possibility?

1qa2ws


Nov 17 '05 #4

"DotNet Coder" <d0*********@yahoo.dot.com> wrote in message
news:Ol**************@TK2MSFTNGP15.phx.gbl...
Well, because, in the case of using ASP.NET, System.Environment.UserName
/System.Environment.UserDomainName will return the name of the currently
logged on user on the server. Not the client using your web application.

In winforms, I suppose you could use System.Environment with no problem.


IMO, OP wasn't asking about ASP.NET, anyway your answer is incorrect. An
empty or a bogus value will be returned by calling
System.Environment.UserName from within asp.net, the reason is that "aspnet"
has no associated profile (and as such no Environment block) as it is not an
interactive login. Even if asp.net run's with domain credentials or as an
interactive login it's profile isn't loaded and the Environment shouldn't be
trusted.
Note that in general calling System.Environment is only a valid option when
the caller is associated with a login that has it's profile loaded (an
interactive login), in all other cases it shouldn't be used.

Willy.


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason | last post by:
I doing some testing with security and ran into the following problem. I want to log into the SQL server (from Query Analyzer) using my domain account. To allow this, I went into Logins section...
5
by: toby | last post by:
Can any one help? I'm trying to use System.Diagnostics.Process.Start to open legacy MS access aplications (ade and mdb files) and vb 6 .exe's using asp.net. There is something confusing going on?!?...
1
by: DMc2004 | last post by:
I have serveral items I would to find out how to do: 1) How to get the username of the person currently logged onto a workstation; 2) How to get the username of who is logged onto a different...
2
by: David Olive | last post by:
Hi guys, I'm having a bit of a problem getting a VB .NET console app to run happily as a scheduled task. The app itself generates a bunch of word documents on a file share on another server by...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
3
by: Hans | last post by:
Hello, I am trying to create a Webrequest. The used Uri is something like "http://username@domain.com:password@www.shfgshfge.com". Note that the username contains an "@"-character. I tried two...
7
by: Peter Afonin | last post by:
Hello, I'm using this code to access a network share from an asp.net page: Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib\") Dim files() As FileInfo = dir.GetFiles("*.eps")...
10
by: Martin Robins | last post by:
I need to access the scheduler service on a network computer in order to manipulate it remotely from .NET; I have all of the necessary code to perform the manipulation and it works - great - but I am...
3
by: Dmitry | last post by:
I am trying to figure out how to pass set of credentials to System.IO Challenge is: App is running under one set of credentials, but via GUI user have a chance to enter another set. I would like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.