Programatically create directory for new user on web site

南楼画角 提交于 2019-12-11 06:49:38

问题


I just uploaded my site to Go Daddy and have code that creates a directory dynamically based on a user id when the user creates an account on my site. It's not creating the directory so I suppose I need to set permissions in some way but I don't have control over IIS since my site's being hosted. How do I programatically set permissions?

if(Directory.Exists(path))
                return true;

try
{
    Directory.CreateDirectory(path);
}

回答1:


You can create a file/sub directory only within the root web directory provided to your website. And GoDaddy might have provided you a login to a control panel using which you can set permissions in your directory. The following is the process to set up permissions on a godaddy account:

  1. Login using your user name/account number and password
  2. Click on My Account
  3. Click on Hosting Account List
  4. Click on Open (the web hosting package you want to open)
  5. Scroll down to content and click File Manager
  6. Select the domain folder you want to set permissions for and click permissions button on the upper control bar
  7. Set the required permissions and click OK.



回答2:


Where you have the path variable, have you tried:

if(Directory.Exists(Server.MapPath(path)))
    return true;

try
{
    Directory.CreateDirectory(Server.MapPath(path));
}

What is the format of path?




回答3:


You need to map the physical directory path using Server.MapPath Method.

string directoryPath = Server.MapPath(path);       

if(Directory.Exists(directoryPath)) 
            return true; 

try 
{ 
    Directory.CreateDirectory(directoryPath ); 
} 

On the web server you can't create a directory or file outside your website virtual directory folder.



来源:https://stackoverflow.com/questions/9407437/programatically-create-directory-for-new-user-on-web-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!