set src property in view to a url outside of the MVC3 project

前端 未结 2 1684
囚心锁ツ
囚心锁ツ 2021-02-14 12:06

I am trying to create an application that will display images that are stored locally on the webserver. Here is what I have in my view, note that \"entry\" are absolute addresse

2条回答
  •  死守一世寂寞
    2021-02-14 12:43

    The above code was useful for me, with a change like this

     System.Web.UI.Page page = new System.Web.UI.Page();
     string filePath = page.Server.MapPath("~/Log/" + fileName);
    
            if (!filePath.StartsWith(filePath))
    
            {
    
                throw new HttpException(403, "Forbidden");
            }
    
            return File(filePath, "Content-Disposition", "attachment;filename=TableImportLog.csv");
    

    }

    the file thrown to the user is with file name like this "attachment;filename=TableImportLog.csv", but i want the file name as "TableErrorLog.csv" need help for the same!

提交回复
热议问题