Error finding the path to save a txt file

0

Good morning, I have a web in c # asp.net and in which I have to access a folder to save some txt files. What happens is that when I run it from a visual studio I can read and write the files in the folder normally, but if I publish it in IIS, it throws the error:

No se puede encontrar una parte de la ruta de acceso 'T:\Temp9720180101.txt'.

Is it a user topic ?, or is the IIS unable to access the local folder because of missing IP?

thanks.

    
asked by Japh Sxas 24.01.2018 в 17:25
source

1 answer

3
  

Why can you access from your application executed from your Visual   Studio?

It is because the process related to the execution of your application uses your credentials to access unit T: , which refers to the shared folder. You can give an exception that you do not use your credentials, because when you create a network drive you have the option to connect with other credentials .

  

Why can not the IIS access the shared folder?

To execute the processes of each application use the group of applications (application pool) assigned to them and therefore, as users of your server, they would not have the necessary permissions to access the shared folder.

That's why you could do:

Step Authentication Configuration

To the commented thing, you could consider using an authentication of step, for it is necessary that you realize in your IIS the following thing:

  • Select the site or application, and choose "Basic configuration"
  • The "Modify site" sale will open, click on "Connect as ..."
  • The "Connect as" sale will open, in it you select "Specific user" and click on "Set ..."
  • The "Set Credentials" sale will open, enter the username and password, and click on "Accept"
  • To verify that the information entered is correct:

  • In the "Modify site" window, click on "Test configuration ..."
  • The "Test Connection" window will open, in which you could verify the Authentication and Authorization result; I should show you the icons in green.
  •   

    As a test you could consider your user account, for greater security what is done is to define an application user in the domain and the necessary permissions are assigned to the shared folder.

    User Spoofing

    Because some policies are not considered the creation of an application user, you would have to access the shared folder through an account. For this it would be necessary to add the package SimpleImpersonation to your web project.

    PM> Install-Package SimpleImpersonation
    

    In the code you would include, for example:

    using (Impersonation.LogonUser("domain", "username", "password", LogonType.NewCredentials))
    {
        var fileText = File.ReadAllText(@"\SharedFile\file.txt");
        Console.WriteLine(fileText);
    }
    

    For this example, what you do is access the shared folder and read the text file.

        
    answered by 24.01.2018 в 23:34