2017-04-21 108 views
1

我正在尝试下载生成的PDF。 C#代码是还好吧,我猜,但问题是,它给了我一个错误:ASP.NET MVC访问被拒绝写入文件夹

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

我试图通过

right click -> properties -> security -> edit -> add 

我找不到任何名为用户授予权限在此文件夹中ASPNET?所以我试图添加NETWORKSERVICE IIS_IUSRS,甚至所有和每个人都不工作..

我在这里做错了什么?

代码:

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

回答

2

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的文件名参数...

相关问题