简体   繁体   中英

c# winforms : getting and using credentials to access a folder on another domain

I am developing ac# Winforms application that runs as a normal user (no elivated privilages) under windows7. The application needs to access a folder that is present on another domain - not the domain the user signed in under.

I would like to know how to ask the user to enter the new credentials needed to access the folder and the files it contains, on the other domain, from within the application.

Ideally, I would like to pop-up a credentials dialog, similar to what windows curently does, asking for the userid, password and domain. I am unsure how to do this and what to do with the values the user would provide so the folder's files can be accessed.

An example would be very good.

thanks c# user

You can used advapi32.dll methods to impersonate a specific user in your code. Have a look at this article.

You can prompt for details using the CredUIPromptForWindowsCredentials function.

If you're connecting to a file share, you don't need to impersonate a user; you can just pass the other credentials to the WNetAddConnection3 function.

To call it from C#, you'll need P/Invoke .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM