We help IT Professionals succeed at work.

Authentication using the NetworkCredential class in .Net

PantoffelSlippers
on
Medium Priority
1,332 Views
Last Modified: 2013-12-17
Hi

I'm trying to write an application that reads files off a network share.  The problem is that the domain requires authentication before the application may access the share.  I'm trying to use the NetworkCredential class to automate this.  I have the appropriate username and password.

Please assist me in using the Network Credential class to achieve this.

I have attached some code

Thanks

'Dim NetC As New System.Net.NetworkCredential
 
        'NetC.Domain = "PRODDOM"
        'NetC.UserName = "admin-s1038920"
        'NetC.Password = "YY9hJ90!hH$"
 
 
         --This prompts for username and password
        Chart1.SaveImage(My.Settings.ImageTargetPath & My.Settings.SaveToImageName, _
                         DataVisualization.Charting.ChartImageFormat.Jpeg)

Open in new window

Comment
Watch Question

PantoffelSlippersOperations Manager

Author

Commented:
Anyone?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Are you talking about impersonation?
PantoffelSlippersOperations Manager

Author

Commented:
TheLearnedOne,

To be honest with you:  I don't know.

I basically don't know what could be a solution for me.

All I'm looking to do is programmtically access a shared folder.

If authentication is required then my code needs to provide it automatically.

If impersonation can help me achieve that then yes, we can have a look at impersonation.

I've just read a couple of articles on impersonation and it seems as if it could be what I'm looking for!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
There are plenty of examples that use impersonation to access a network share.

Here is a C# CodeProject article:

Windows Impersonation using C#
http://www.codeproject.com/KB/cs/cpimpersonation1.aspx

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
PantoffelSlippersOperations Manager

Author

Commented:
Thank you TheLearnedOne,

I was unfamiliar with Impersonation up until now.

Well, I still am but at least now I know about it.

I'll check out the link  - maybe it'll solve my problem.

Post back soon

Thanks
PantoffelSlippersOperations Manager

Author

Commented:
Thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.