【问题标题】:ASP.NET MVC Acces denied to write in folderASP.NET MVC 访问被拒绝写入文件夹
【发布时间】:2017-04-21 11:16:42
【问题描述】:

我目前正在尝试下载生成的 PDF。 我猜 C# 代码没问题,但问题是它给了我一个错误:

Access to the path 'C:\temp' is denied.

我尝试通过

授予此文件夹的权限
right click -> properties -> security -> edit -> add

我找不到任何名为 ASPNET 的用户?所以我尝试添加 NETWORKSERVICE IIS_IUSRS 甚至 All and Everyone 都不起作用..

我在这里做错了什么?

代码:

public ActionResult GeneratePDF(WorkReportModel model)
{
    return File("C:\\temp", "application/pdf", "MyRenamedFile.pdf");
}

【问题讨论】:

    标签: c# asp.net asp.net-mvc


    【解决方案1】:

    C:\Temp 是一个目录,所以你不能将它作为文件发送..... 我确定你的意思是这样的;

    public ActionResult GeneratePDF(WorkReportModel model)
    {
        return File("C:\\temp\\theActualFileName.pdf", "application/pdf", "MyRenamedFile.pdf");
    }
    

    文件方法见 MSDN 文档:

    https://msdn.microsoft.com/en-us/library/system.web.mvc.controller.file(v=vs.118).aspx#M:System.Web.Mvc.Controller.File%28System.String,System.String,System.String%29

    protected internal virtual FilePathResult File(
        string fileName,
        string contentType,
        string fileDownloadName
    )
    Parameters:
    
    fileName Type: System.String
    The path of the file to send to the response.
    

    您正在将 C:\temp 发送到 FILE 名称参数...

    【讨论】:

      猜你喜欢
      • 2011-05-24
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      相关资源
      最近更新 更多