【发布时间】:2016-07-13 20:22:03
【问题描述】:
我有一个要显示给用户的 pdf。当我从 IDE 运行代码时,它显示没有问题,但是当我将应用程序发布到服务器时,它会生成 404。
我已将文件 Instructions.pdf 放在我创建的名为 /Files 的文件夹中
这是我的观点链接:
<h2>Placeholder</h2>
<p>
Click below for instructions on how to use the tool.
</p>
<p><a class="btn btn-default" href="/Home/InstructionsPDF">Instructions »</a></p>
这是控制器动作:
public ActionResult InstructionsPDF()
{
return File(HostingEnvironment.MapPat("~/Files/Instructions.pdf"), "application/pdf"
}
查看此问题后,一个常见的解决方案是将构建操作更改为“内容”。我检查了pdf上的属性,它们如下:
Browse to URL |
Build Action | Content
Copy to Output Directory | Copy always
Custom Tool |
Custom Tool Namespace |
任何建议都非常感谢欢迎,感谢您的宝贵时间。
【问题讨论】:
-
您可以尝试使用 HttpContext.Current.Server.MapPath
标签: c# asp.net-mvc