Asp.net Access To Network Share

how to access shared folder in asp net web application
how to access network files from iis applications
iis virtual directory network share access denied
iis access mapped drive
asp net access remote file share
iis not able to access the folder
give iis user access to network share
application pool identity access network share

I have an ASP.NET app which needs to save files to a network share (Samba).

The share requires a username and password to connect.

I have mapped a persistent drive to the share and provided the login credentials whilst logged in to the server as DOMAIN\WEBUSER.

I have changed the virtual directory which hosts my app to use the DOMAIN\WEBUSER account instead of the IWAM account.

However the user still cannot see the mapped drive.

What am I missing out?

It is best to use the UNC if you can as the mapped drives generally are linked to the interactive user and the virtual directory is probably connecting with a service or netwrok login type.

Another possible fix is described in this KB articleError occurs when you configure IIS to use a Samba network share as its root. Excerpted below.

Important These steps may increase your security risk. These steps may also make the computer or the network more vulnerable to attack by malicious users or by malicious software such as viruses. We recommend the process that this article describes to enable programs to operate as they are designed to or to implement specific program capabilities. Before you make these changes, we recommend that you evaluate the risks that are associated with implementing this process in your particular environment. If you decide to implement this process, take any appropriate additional steps to help protect the system. We recommend that you use this process only if you really require this process.

Warning This method involves a security risk because the user who created the mapping must remain logged on to the local console. Therefore, the only security is by locking the computer. To work around this problem, do the following:

  1. Map a drive letter to \servername\iisroot using "root" and "password."
  2. In the Samba virtual directory, change the home directory from Share on Another Computer to Local Directory, and then specify the drive letter that you mapped in step 1.
  3. Restart the Web site, and then test it by browsing.

Correct way to access a file share, We have a network share that is accessible to only a particular domain user. When I try to put impersonate in the web.config I get the error saying� I have an ASP.NET website, that has to access a shared network drive. The shared network drive is on an EMC path or ECS. The management module for the shared drives is EMC made, accessible through a browser, so I am assuming. In the web.config, I have the drive names as Z:, R: etc.. I am able to mount them on the cmd line with the following line.

Did you try mapping the drive in code? Here is a class for doing just that...

public static class NetworkDrives
    {
        public static bool  MapDrive(string DriveLetter, string Path, string Username, string Password)
        {

            bool ReturnValue = false;

            if(System.IO.Directory.Exists(DriveLetter + ":\\"))
            {
                DisconnectDrive(DriveLetter);
            }
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardOutput = true;

            p.StartInfo.FileName = "net.exe";
            p.StartInfo.Arguments = " use " + DriveLetter + ": " + Path + " " + Password + " /user:" + Username;
            p.Start();
            p.WaitForExit();

            string ErrorMessage = p.StandardError.ReadToEnd();
            string OuputMessage = p.StandardOutput.ReadToEnd();
            if (ErrorMessage.Length > 0)
            {
                throw new Exception("Error:" + ErrorMessage);
            }
            else
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool DisconnectDrive(string DriveLetter)
        {
            bool ReturnValue = false;
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardOutput = true;

            p.StartInfo.FileName = "net.exe";
            p.StartInfo.Arguments = " use " + DriveLetter + ": /DELETE";
            p.Start();
            p.WaitForExit();

            string ErrorMessage = p.StandardError.ReadToEnd();
            string OuputMessage = p.StandardOutput.ReadToEnd();
            if (ErrorMessage.Length > 0)
            {
                throw new Exception("Error:" + ErrorMessage);
            }
            else
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }

    }

ASP.NET application cannot access network share even with , It has been long time ago but maybe it could be useful for someone. Try and use the class NetworkConnection to access to the shared folder. We can do using Asp.net Impersonate. We can implement asp.net impersonate in different way, mean by programmatically or using web.config file. Synchronize the IUSR account between the two machines Here is list of steps that you have to follow to achieve it. 1. Setup IIS to Allow us to Use Network files and Folder 2. Enable Impersonate in Asp.net.

It's been a while (6 or 8 years) since I've done something like this, but as I recall, I also had to run the APP Pool as the domain user that had access to the network share in order for IIS to be able to serve up files from it.

[Solved] Accessing network drive from ASP.NET through network , Hide Expand Copy Code. I just solved this problem on my own after failing to find a proper way to do it on Google. This forum still comes up� For accessing network drive we are using NetworkCredential and MPR library for accessing files and directory of network folder. For accessing network drive we have to pass network path and its username and password for connecting with the network then we can access files and directory inside network drive. Let's start coding.

How to Access Network Files using asp.net, Introduction. Here I am Showing How to Access Network Files and Folder using asp.net. Background. When we Develop web application to� Asp.net Access To Network Share. I have an ASP.NET app which needs to save files to a network share (Samba). The share requires a username and password to connect. I have mapped a persistent drive to the share and provided the login credentials whilst logged in to the server as DOMAIN\WEBUSER.

Permissions Issue with ASP.NET Application Using Network Share , Both will have to be setup in order to access a network share. If you right-click a shared folder, you'll need to set up permission in both the Sharing� All access to the computer that shares the network resources is performed in the context of the person specified under the Connect As.. dialog box. This occurs no matter what kind of authentication is configured for the virtual directory. By using this option, all files on the network share are available from browsers that access the IIS computer.

How Do I Setup IIS to Allow it to Use Network Resources?, If your account is allowed to write to the folder at FileServer, your file access code Instead of code dealing with files in your ASP pages directly, you should now add the names of DLL's which are used to access network resources in .NET. Hi urir10, In ASP.NET web application, you can programmtically impersonate under a specific windows account. For your scenario, you can use this approach to impersonate under the certain domain account (which has permission to access the remote share) before executring the file accessing code.

Comments
  • Honestly, the workaround suggested by MS in this article is pretty terrible advice.
  • That's awesome. Having problems getting impersonation to work with a particular network share but this works. Thanks!