目前,用户将条形码文件上传到服务器,然后服务器对此进行解码并将响应发送回客户端。当我在本地计算机上运行Web应用程序时,这一切都正常,但是当我将它发布到我的网站托管(Gear Host)时,它不起作用。
这是我的代码:
客户端:
<form action="" method="post" enctype="multipart/form-data">
<label class="btn btn-default btn-file btn-lg">
Start Audit
<input type="file" accept="image/*;capture=camera" name="file" id="file" onchange="this.form.submit();" style="display: none;">
</label>
</form>
服务器端:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/Temp"), fileName);
file.SaveAs(path);
// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// load a bitmap
Bitmap bitmap = new Bitmap(path);
Bitmap resized = new Bitmap(bitmap, new Size(400, 400));
// detect and decode the barcode inside the bitmap
var result = reader.Decode(resized);
// Delete file once we have finished with it
/*if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}*/
// do something with the result
if (result != null)
{
return RedirectToAction("../Room/" + result.Text);
//txtDecoderType.Text = result.BarcodeFormat.ToString();
//txtDecoderContent.Text = result.Text;
}
// Decode error
else
{
return RedirectToAction("Index");
}
}
// File error
else
{
return RedirectToAction("Index");
}
}
感谢任何帮助,这是我需要联系我的主机的吗?