本文介绍了无法创建路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有以下代码来检查路径,如果不存在则创建。但它一直有错误返回。
代码:
Hello,
I have the following code to check for path, if not exist create. But it keeps returning with an error.
Code:
string path1 = "~/uploads/" + getpono + "/" + getmrr + "/";
if (!System.IO.Directory.Exists(path1))
{
System.IO.Directory.CreateDirectory(path1);
}
错误:
Error:
Access to the path '~/uploads/147302/BFM-400523-1001/' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path '~/uploads/147302/BFM-400523-1001/' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
之前我能够创建文件夹,但所有突然我不能再创造了。我确定该文件夹是IUSER_MACHINENAME的权限,但仍然没有。
有什么想法吗?
I was able to create the folder before, but all of sudden i can not create anymore. I have made sure the folder as permissions for IUSER_MACHINENAME but still nothing.
Any idea?
推荐答案
string path1 = Server.MapPath("~/uploads/" + getpono + "/" + getmrr + "/");
尝试从.Net用户的完全控制设置访问权限在哪里阅读/保存文件。
希望它能正常工作......!
Try setting the access permissions to "Full control" for the .Net user from where you are reading/saving the files.
Hopefully it will work ...!
这篇关于无法创建路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!