Obtain Network Credentials from Current User in Windows Authentication Application

余生颓废 提交于 2019-12-03 11:39:59

问题


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..


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11414266/obtain-network-credentials-from-current-user-in-windows-authentication-applicati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!