-1

I am trying to write a file to a specific location on a shared folder. This shared folder is accessible to only few people. But in the code, I want to take either windows credentials or give certain username and password. But, when I try it always shows me Access denied. I want to pass certain credentials or windows network login credential. How can I achieve that ?

            string destFilename = @"\\test.net\excel\docs\test.xls";
            System.Net.WebClient client = new System.Net.WebClient();
            WebDownload w = new WebDownload(3600000);
            UTF8Encoding objUTF8 = new UTF8Encoding();
            byte[] data = w.DownloadData();
            WebRequest request = WebRequest.Create(destFilename);
            File.WriteAllBytes(destFilename, data); //ACCESS DENIED

EDIT

It is a console application

hello temp8
  • 21
  • 1
  • 4
  • ASP.NET does not run as the user who's logged in. You'll need to set up IIS to run it as a specific account which has access, or possibly grant the user that asp.net runs under permission to the folder ([see here](http://stackoverflow.com/questions/4269431/asp-net-which-user-account-running-web-service-on-iis-7) ) – Steve's a D Apr 10 '15 at 19:01
  • That is not always true. If the web server is on a corporate domain and the web site is set up to use Integrated Windows Authentication, then the web page does run as the calling user. Not saying that is the case, but the OP did not specify. – Kevin Apr 10 '15 at 19:07
  • I'm not positive what you mean, but I'm still pretty noobish, so I'll take your word for it :) – Steve's a D Apr 10 '15 at 19:10
  • If it is a console app you should remove the asp.net tag – Aaron Apr 10 '15 at 19:28
  • I think a console app would run with the permissions of the logged in user. Not sure though. – Aaron Apr 10 '15 at 19:43
  • How can I get but. i want to impersonate user – hello temp8 Apr 10 '15 at 20:05

1 Answers1

0

You can setup IIS Application Pool Identities in order to run the application as the user that has access. You can find more information here:

http://www.iis.net/learn/manage/configuring-security/application-pool-identities

Aaron
  • 1,361
  • 1
  • 13
  • 30