2017-04-21 58 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的文件名參數...

相關問題