[英]Allow users Create Folder inside a asp.net website
I am developing a asp.net website. 我正在开发一个asp.net网站。 I want to allow users to create their own folders inside the website.
我想允许用户在网站内创建自己的文件夹。
string pathToCreate = "~/path/sub folder";
if (Directory.Exists(Server.MapPath(pathToCreate)))
{
// folder exist message
}
else
{ //cerate folder
Directory.CreateDirectory(Server.MapPath(pathToCreate));
base.OnLoad(e);
}
This working when I am debugging using visual studio. 当我使用Visual Studio进行调试时,此功能有效。 But after when I host it in IIS it showing the error of Access denied to the previously specified path
但是当我将其托管在IIS中后,它显示了拒绝访问先前指定路径的错误
Access to the path 'C:\inetpub\wwwroot\sample_site\resources\users_folder' is denied.
Line 47: Directory.CreateDirectory(Server.MapPath(pathToCreate));
By default, write access is not allowed for the ASP.NET process inside the web directory. 默认情况下,不允许对Web目录内的ASP.NET进程进行写访问。
There is an exception however. 但是有一个例外。 You can write to the
App_Data
directory. 您可以写入
App_Data
目录。 Just create folders inside there. 只需在其中创建文件夹。
It needs the whole path - something like "C:\\inetpub\\wwwroot\\sample_site\\resources\\users_folder".
它需要整个路径-类似于
"C:\\inetpub\\wwwroot\\sample_site\\resources\\users_folder".
Use Server.MapPath("~/YourApplication/folder") + @"\\folder"
to get physical path of the folder. 使用
Server.MapPath("~/YourApplication/folder") + @"\\folder"
获取Server.MapPath("~/YourApplication/folder") + @"\\folder"
物理路径。
Referance: 全球化志愿服务青年:
http://forums.asp.net/t/1622617.aspx/1 http://forums.asp.net/t/1622617.aspx/1
Either: 或者:
Create a new user on the server, give this user write permissions and get the website to impersonate this user by adding to the web.config: 在服务器上创建一个新用户,授予该用户写权限,并通过添加到web.config来获得该网站来模拟该用户:
< identity impersonate="true" userName="username" password="password"/ > <identity impersonate =“ true” userName =“用户名” password =“密码” />
I've always found 2. works better in our environment. 我一直发现2.在我们的环境中效果更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.