I was wondering whether it was possible to obtain the current user object and get their credentials so that I can pass them along to a NetworkCredential
object which I am using to connect to my AX .NET Business Connector. As, at the moment I'm having to specify it connect as a specific user which I set when I instantiate a NetworkCredential
object:
private NetworkCredential nc = new NetworkCredential("myUser", "myPassword", "myDomain");
I was hoping to do something like: private NetworkCredential nc = (NetworkCredential)HttpContext.User;
but obviously that won't work...
That way, it's easier to keep track of which user has created a sales order for example, as at the moment everything gets created by the user I have specified..
Go to Control Panel > User accounts. From there, navigate to Credential Manager > Windows Credentials. You will see a field Add Windows Credentials, tap on it. In this menu, you can add the computer's name you want to access, username and password.
When a domain account is used, network authentication occurs transparently and in the background via Kerberos or TLS/SSL. Users who use a local computer account must give user credentials such as a username and password while trying to gain access to a network resource.
A client that wants to authenticate itself with the server can then do so by including an Authorization request header with the credentials. Usually a client will present a password prompt to the user and will then issue the request including the correct Authorization header.
CredentialCache.DefaultNetworkCredentials
?
The credentials returned by
DefaultNetworkCredentials
represents the authentication credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application.
I don't fully understand your question, but is your call coming from ASP.NET that you require the credentials? You could attempt:
Uri uri = new Uri("http://tempuri.org/");
ICredentials credentials = CredentialCache.DefaultCredentials;
NetworkCredential credential = credentials.GetCredential(uri, "Basic");
Assuming your user has already authenticated via a Membership Provider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With