![](/img/trans.png)
[英]ASP Zero :System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\log4net.config'
[英]Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx'
我有一个 MVC 应用程序,它读取和上传一个 Excel 文件并在应用程序中处理该文件,在我的本地机器上一切正常,但是一旦我部署到服务器,我就会收到上面的以下错误。 我已将 IIS 应用程序池用户的权限添加到根文件夹,但是一旦我通过本地计算机上的应用程序浏览文件,它就会失败并出现上述错误。 如果我在部署的服务器上测试它,它工作正常。 知道这是什么,我看过很多关于此的帖子,尝试了建议但没有运气。 任何想法,请参阅下面我的代码。
try
{
if (file.ContentLength > 0)
{
var fileName = file.FileName;
var targetFolder = Server.MapPath("/");
string targetPath = Path.Combine(targetFolder, fileName);
file.SaveAs(targetPath);
你应该使用波浪号(~)来指向应用程序的根
Server.MapPath("~/");
最好使用子文件夹(确保有那个文件夹)
Server.MapPath("~/uploads/")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.