无法创建路径 [英] Not able to create path

查看:74
本文介绍了无法创建路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有以下代码来检查路径,如果不存在则创建。但它一直有错误返回。



代码:



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?

推荐答案

您无法直接使用此类路径。 〜/ * ...形式的路径是相对于为站点配置的根目录的路径。但.NET API(比如 System.IO )并不知道这条路径。您可以通过 MapPath 从HTTP请求中找到它:

HttpServerUtility.MapPath Method(String)(System.Web) [ ^ ]。



参见: HttpServerUtility.MapPath方法(字符串)(System.Web) [ ^ ]。



-SA
You cannot directly use such paths. The paths in the form "~/*..." are the paths relative to the root directory configured for your site. But the .NET API (say, System.IO) does not "know" this path. You can find it from your HTTP request via MapPath:
HttpServerUtility.MapPath Method (String) (System.Web)[^].

See also: HttpServerUtility.MapPath Method (String) (System.Web)[^].

—SA


使用下面的代码:

Use below code :
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 ...!


错误是准确的。我建议进入IIS并将应用程序池的标识设置为对文件系统具有权限的帐户。
The error is accurate. I suggest going into IIS and setting the identity of the application pool to an account that has permissions to the file system.


这篇关于无法创建路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆