将图像上载到IIS服务器失败

时间:2017-07-13 11:16:41

标签: asp.net image iis file-upload upload

下面是我的控制器代码,用于将图像上传到我的IIS服务器,本地工作正常但是在我的生产IIS服务器上运行时,每次都返回异常上载失败。有没有人有解决方案?

using System;  
using System.Collections.Generic;  
using System.IO;  
using System.Linq;  
using System.Web;  
using System.Web.Mvc;  

namespace website.Controllers
{
[Authorize]
public class UploadController : Controller
{

// GET: Upload  
public ActionResult Index()
{
    return View();
}
[HttpGet]

public ActionResult UploadFile()
{
    return View();
}
[HttpPost]

public ActionResult UploadFile(HttpPostedFileBase file)
{
    try
    {
        if (file.ContentLength > 0)
        {
            string _FileName = Path.GetFileName(file.FileName);
            string _path = Path.Combine(Server.MapPath("~/Content/Images"), _FileName);
            file.SaveAs(_path);
        }
        ViewBag.Message = "File Uploaded Successfully!!";
        return View();
    }
    catch
    {
        ViewBag.Message = "File upload failed!!";
        return View();
    }
}
}  
}

0 个答案:

没有答案