【问题标题】:File upload Issue for External user outside the application - ASP.NET MVC Impersonation应用程序外部外部用户的文件上传问题 - ASP.NET MVC 模拟
【发布时间】:2021-05-28 02:54:21
【问题描述】:

我有一个要求,我想创建一个调查表,并且用户可以选择上传文件。该网站是一个 ASP.NET MVC 应用程序。

这些用户只能访问调查表,而不能访问应用程序中的任何其他页面。要上传到位于应用程序托管的同一服务器中的共享文件夹的文件。

文件夹的访问权限仅适用于特定的 AD 组。上传文件的外部用户不属于该 AD 组。

     [HttpPost]
    public JsonResult Upload()
    {
         string fileUniqueName = string.Empty;

        try
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];
                string fileName = file.FileName;
                fileUniqueName = string.Format("{0}_{1}_{2}",
                Path.GetFileNameWithoutExtension(file.FileName),
                DateTime.Now.ToString("yyyyMMdd_HHmmss_FFF"),
                Path.GetExtension(file.FileName));
                string tempFileUploadFolderPath = ConfigurationManager.AppSettings["TempFolderPath"];
                Directory.CreateDirectory(tempFileUploadFolderPath);
                string fileFullpath = Path.Combine(tempFileUploadFolderPath, fileUniqueName);
                file.SaveAs(fileFullpath);
            }
        }
        catch(Exception)
        {
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return new JsonResult
            {
                Data = ""
            };
        }
        
        return new JsonResult
        {
            Data = fileUniqueName
        };
    }

我在 web.config 中有以下设置

<authentication mode="Windows" />
<identity impersonate="true" />

任何人都可以指导如何在这种情况下执行文件上传功能吗?我们可以对冒充做任何事情吗?

【问题讨论】:

    标签: .net asp.net-mvc file-upload iis-7 impersonation


    【解决方案1】:

    是的,可以做到。

    只需将应用程序池的身份设置为 AD 组中的用户之一,以便应用程序有权将调查存储在共享文件夹中。

    【讨论】:

    • ..但是在上传时,它以登录用户的身份运行,因此权限被拒绝。如何在 AppPool Identity 中运行特定的文件上传代码???
    • 我在你最新的帖子里回答了这个问题,你可以查一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 2010-12-30
    相关资源
    最近更新 更多