I've got a working website that I can upload and download files to a folder within the project locally. However when I use IIS to host the website across LAN, I get a 404 error when trying to download files - I can upload the files fine and they appear in the correct folder.
Error:
HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Here are my controllers.
Download controller:
[HttpGet]
public virtual ActionResult Download(string file)
{
string fullPath = Path.Combine(Server.MapPath("~/SupportAttachments/"), file);
return File(fullPath, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", file);
}
Upload Controller:
[HttpPost]
public JsonResult UploadFiles(string id)
{
try
{
foreach (string file in Request.Files)
{
var hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
continue;
var fileContent = Request.Files[file];
if (fileContent != null && fileContent.ContentLength > 0)
{
// get a stream
var stream = fileContent.InputStream;
// and optionally write the file to disk
var fileName = id + " " + hpf.FileName;
var path = Path.Combine(Server.MapPath("~/SupportAttachments/"), Path.GetFileName(fileName));
// Save the file
hpf.SaveAs(path);
}
}
}
catch (Exception)
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return this.Json("Upload failed");
}
return this.Json("File uploaded successfully");
}
Can anyone advise me as to why I can't download files when hosting via IIS?