locked
CreateDirectory functionality for anonymous users in load balanced environment RRS feed

  • Question

  • User-1690212949 posted

    Hello,

    I'm in the process of moving a website from a single server environment to a load balanced environment.  Part of this application allows for users to upload files to the server.  Also, when a new agency starts to use the application, there is a possibility that a directory will need to be created on the server to accommodate that new agency.  In the single server environment, the following code works just fine:

    If Not Directory.Exists(DocumentDirectory) Then

         Directory.CreateDirectory(DocumentDirectory)

    End If

    In the load balanced environment, a share needed to be created on each server so that the file could be uploaded to both.  Since the share is involved, are there any sort of special security considerations when trying to create a directory?  I guess my question would be...if you happened to have loaded the webpage on one server, would you even be capable of creating the directory on the second server, even when a share has been created and the permissions are set to a fairly low level?

     

    Thursday, February 26, 2015 6:29 PM

All replies

  • User1711366110 posted

    CCGPlayer

    In the load balanced environment, a share needed to be created on each server so that the file could be uploaded to both.  Since the share is involved, are there any sort of special security considerations when trying to create a directory?  I guess my question would be...if you happened to have loaded the webpage on one server, would you even be capable of creating the directory on the second server, even when a share has been created and the permissions are set to a fairly low level?


       As per your case, First, remember that the directory will appear on the server, not the client. You also have to have the rights to create the folder. Finally, in a load balanced environment the folder will appear only on the server that created it, it won't be replicated unless there is some background service that does that for you.
    you can try like below :

    var DocumentDirectory= Server.MapPath("~/App_Data/uploads/random");
    
    If Not Directory.Exists(DocumentDirectory) Then
    
         Directory.CreateDirectory(DocumentDirectory)
    
    End If
    

    Click here to know more about the Directory.CreateDirectory method.
    --
    with regards,
    Edwin

    Sunday, March 1, 2015 10:10 PM
  • User2053451246 posted

    Why not have a shared directory on one server that all save to?

    Sunday, March 1, 2015 11:27 PM
  • User753101303 posted

    Hi,

    This is not really what I would call something special. As usual the account under which your app runs will need to be able to create a directory at this location.

    As pointed by others not sure about your design. On one side it seems you do have a common network share and on another side it looks like you want also to create as well a directory on a "second server"? (is this the file server or the 2nd web server ?)

    Decide where to store your files. See also what could be done at the OS level if you really need some kind of replication rather than trying to keep both servers in sync by using your app alone (if this is your intent).

    Tuesday, July 28, 2015 7:54 AM
  • User-625491883 posted

    Please use fixed server name in your code, change your code into below. don't care about which server handler the request, save and access files into only one server.

    If Not Directory.Exists("\\fixed server name or fixed IP address \C$\foldername") Then

         Directory.CreateDirectory(\\fixed server name or fixed IP address \C$\foldername)

    End If

    other way. you create a mapping table to configure user's file mapping to server address. you can put files into different server. by the only one mapping table. you can figure out the right server address.

    Thursday, September 17, 2015 4:52 AM