问题
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:
- Login using your user name/account number and password
- Click on My Account
- Click on Hosting Account List
- Click on Open (the web hosting package you want to open)
- Scroll down to content and click File Manager
- Select the domain folder you want to set permissions for and click permissions button on the upper control bar
- 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