Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在ASP.NET MVC中,对路径的访问被拒绝_Asp.net Mvc_Iis 7_Virtual Directory - Fatal编程技术网

Asp.net mvc 在ASP.NET MVC中,对路径的访问被拒绝

Asp.net mvc 在ASP.NET MVC中,对路径的访问被拒绝,asp.net-mvc,iis-7,virtual-directory,Asp.net Mvc,Iis 7,Virtual Directory,我试图使用以下代码创建目录: Directory.CreateDirectory("localhost/attachments/7075"); 但它返回了“对路径'localhost/attachments/7075'的访问被拒绝”。 请注意,附件来自网络共享文件夹。我使用IIS上的addvirtualdirectory添加了它 我所做的是: 尝试在共享文件夹中手动创建文件夹,我可以 我试图检查IIS\u IUsers文件夹中的证券,它处于完全控制状态 您需要使用Server.MapPath

我试图使用以下代码创建目录:

Directory.CreateDirectory("localhost/attachments/7075");
但它返回了
“对路径'localhost/attachments/7075'的访问被拒绝”。

请注意,
附件
来自网络共享文件夹。我使用IIS上的
addvirtualdirectory
添加了它

我所做的是:

  • 尝试在共享文件夹中手动创建文件夹,我可以
  • 我试图检查
    IIS\u IUsers
    文件夹中的证券,它处于
    完全控制状态

您需要使用
Server.MapPath()
来使用与虚拟路径对应的物理文件路径

Directory.CreateDirectory(Path.Combine(Server.MapPath("~/attachments"), "7075"));

您需要使用
Server.MapPath()
来使用与虚拟路径对应的物理文件路径

Directory.CreateDirectory(Path.Combine(Server.MapPath("~/attachments"), "7075"));