c# - Get Windows logged in user's email when offline -


We currently use this code to get the user's email:

  var CurrentUsersEmail = UserPrinnal Present. Email address;   

When on the network it works fine. However, we have a laptop user who runs our code remotely and in a disconnected position. The above code causes this exception when:

  System.DirectoryServices.AccountManagement.PrincipalServerDownException Message: "The server could not be contacted."   

Does anyone know the way to get an email from an existing user who will work on network / connect and when it is disconnected?

Update: If you are wondering why we want to do this, there are several ways in our system that send alerts via email. When our developers are running automated tests, we want the email to be sent to the currently logged-in user (i.e., the developer) so that they can verify the format.

You can rewrite your application so that it UserPrincipal.Current.EmailAddress For the first time, and perhaps whenever it is online, and then working on the offline, the user's application stores or saves that information in the registry for reference. It will need to run at least one online before working offline, but I do not know how you can do this without asking a user or using a config file.

There is no way System.DirectoryServices.AccountManagement Namespace will work offline. It is asking how the database can be used without the use of any database.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -