views:

525

answers:

1

Hello,

I have ASP.NET project which do some file access and manipulation, the methods which I use for file access are below. Now I need to access files on another server shared folder, how to do that? I easily can change file path to shared folder path but I get "can't access" error because shares are password protected. As I understand I need somehow to send credentials to remote server before executing methods below. How to do that?

FileStream("c:\MyProj\file.doc", FileMode.OpenOrCreate, FileAccess.Write)
Context.Response.TransmitFile("c:\MyProj\file.doc");

Regards, Tomas

+2  A: 

Hi Tomas

An ASP.NET application (by default) will execute in IIS6 under the "ASPNET" computer account. You therefore have a couple of options:

  • Configure your ASPNET application to run under a (weak) domain account with permissions to access the remote computer's share
  • Set the permissions on the share to enable access to "Everybody" (not recommended)
  • Disable Forms authentication and use Windows authentication in your ASP.NET app. Turn off impersonation in web.config and IIS should pass the credentials of the user who is currently using your web application through to the underlying share (I think).

The latter option is only useful, of course, if your users all have domain accounts on your intranet, for instance. I'll continue to look around for ways to add credentials but I'm not sure off the top of my head if that's possible.

HTH,

Richard.

Richard
Thank you for your answer! Not of three your suggested solution fit my needs. The second one look easy to implement but it will give access to all users for share and unfortunately Windows do not allow to completely hide shares. I have tried to use Mapped Network Drive to map shared folder as drive, unfortunately that does not works on IIS6 too.
Tomas
@Tomas - mapping a network drive isn't really the best way to do it since they're mapped per logged-on user, not per computer. There is a work around for this on Scott Hanselman's blog if you do need to do this though. You can try creating a new domain user account (maybe called WebShare or something) and give it read permissions to your network share. You can then right-click the application in IIS6, go to Properties, and change the worker process to "WebShare". This will force you web application to assume the "WebShare" identity, and thus it will be able to access the share.
Richard
Richard, your suggestion works! Thank you for your help.
Tomas