简体   繁体   English

ASP.NET C#-动态创建上传目录?

[英]ASP.NET C# - Create upload directory on the fly?

    public class UploadHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
        ...

        // Create the directory if needed...
        if (!Directory.Exists(uploadDir))
        {
            System.Security.AccessControl.DirectorySecurity ds = new System.Security.AccessControl.DirectorySecurity(RivWorks.AppSettings.UploadRoot, System.Security.AccessControl.AccessControlSections.All);
            Directory.CreateDirectory(uploadDir, ds);
        }
        ...
    }

I have the above snippet of code for a ASHX file and it works fine in my local environment. 我上面有一个ASHX文件的代码片段,它在我的本地环境中运行良好。 As soon as I push it to a server environment I don't get an error, it appears to have built the directory, yet when I check for it - well - it is not there. 将其推送到服务器环境后,我没有收到任何错误,它似乎已经建立了目录,但是当我检查它时-很好-它不存在。 When I run it via a FLEX app we are getting this error: 当我通过FLEX应用程序运行它时,出现此错误:

Error #2038: File I/O Error. 错误#2038:文件I / O错误。 URL: http://[ourdomain].com/UploadHandler.ashx?CompanyID=d229cc80-ca96-4a8a-992c-80c94ac2c6b4 网址: http:// [ourdomain] .com / UploadHandler.ashx?CompanyID = d229cc80-ca96-4a8a-992c-80c94ac2c6b4

Is there anything I am missing? 我有什么想念的吗?

UPDATE: 更新:

  1. I can create files anywhere on disk 我可以在磁盘上的任何位置创建文件
  2. I cannot create directories anywhere on disk. 无法在磁盘上的任何位置创建目录。

I get this error now when trying to create a directory: 现在尝试创建目录时出现此错误:

The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation. 该进程不具有此操作所需的“ SeSecurityPrivilege”特权。

Have you checked that your program has the correct access rights to the relevant directories on the server? 您是否检查过程序对服务器上相关目录的正确访问权限?

If you don't have the right permissions either because the account you are using is restricted or the directories are locked down you will see this error. 如果由于使用的帐户受到限制或目录被锁定而没有正确的权限,则会看到此错误。

Just simple use mkdir() function to create directory. 只需使用mkdir()函数创建目录即可。 to define a path you may use SERVERMAPPATH attribute. 定义路径,您可以使用SERVERMAPPATH属性。

use within try catch endtry block to avoid already existing or any other Error. 在try catch endtry块内使用,以避免已经存在或任何其他错误。

Is the site runs with identity impersonation=true? 该网站是否以标识模拟= true运行? If so it runs under your credentials/authorization in your environment 如果是这样,它将在您的环境中以您的凭据/授权运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM