Reputation: 4031
I have create a directory uploads
in the Content
directory and inside the uploads
dir i create a directory at the time of creation of user account. This setup works fine on the development setup but when i publish the site on my local IIS
i get a access denied error.
Access to the path 'C:\inetpub\wwwroot\Content\uploads/d1bed3b7-f9e1-486a-953a-37abc7b99dad' is denied.
I have a shared hosting environment, the question i want to ask is, will i be able to set the permissions on the shared hosting environment?
What are the alternatives?
EDIT
here is code(tnx to @Marko) for creating the directory for the user
string UserGUID = Guid.NewGuid().ToString();
string path = HostingEnvironment.MapPath(@"~/Content/uploads");
Directory.CreateDirectory(path+"/" + UserGUID);
EDIT
after changing the code the error message has improved
Access to the path 'C:\inetpub\wwwroot\Content\uploads\ab569312-c487-4a08-bf49-99f7c69303f6' is denied.
Upvotes: 0
Views: 443
Reputation: 72230
There's a problem with the path, you have the wrong slash /
C:\inetpub\wwwroot\Content\uploads--------->/<----------d1bed3b7-f9e1-486a-953a-37abc7b99dad'
As long as the \uploads\
path has writable permissions any folders/files you create within that folder should inherit permissions from the parent.
EDIT
I'm not 100% sure why it works in cassini but change your code to this (it uses Path.Combine
) instead of adding a slash manually (which is actually the wrong slash).
string UserGUID = Guid.NewGuid().ToString();
string path = HostingEnvironment.MapPath(@"~/Content/uploads");
string userPath = Path.Combine(path, UserGuid);
Directory.CreateDirectory(userPath);
If all of this fails, contact your hosting provider to set writable permissions to the /uploads/
folder or use the Administration panel if you have one.
Upvotes: 2