Asp.net 将图像上载到IIS服务器失败
下面是我的控制器代码,用于将映像上载到我的IIS服务器,在本地这可以正常工作,但在我的生产IIS服务器上运行时,每次都会返回异常上载失败。有人有解决办法吗Asp.net 将图像上载到IIS服务器失败,asp.net,image,iis,file-upload,upload,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 { [Au
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();
}
}
}
}
Evar您收到的错误消息是什么?您好,我不确定如何访问详细的错误消息,我刚刚收到视图中的viewbag.message“文件上载失败”。我相信错误可能是由于我的IIS服务器设置造成的,但我不确定我需要更改什么您无法看到详细的错误消息,因为您正在吞咽它。您需要捕获异常
catch(exception exception)
,然后从捕获的异常exception.Message
或exception.ToString()中获取详细信息。最好把它们记录在某个地方。