【发布时间】:2015-08-27 03:05:18
【问题描述】:
Android 浏览器无法上传文件,但在 PC 浏览器中可以正常上传。我的 MVC 代码在本地 IIS express 中运行良好
[HttpPost]
public string UploadJson(string id)
{
try
{
string uploadFial = "noSave";
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
if (string.IsNullOrWhiteSpace(id)) id = Request.Params["id"];
string fileName = id + Path.GetExtension(file.FileName);
string path = Path.Combine(Server.MapPath("~/Images/"), fileName);
logPath = Path.Combine(Server.MapPath("~/Images/"), "log.txt");
file.SaveAs(path);
return (Request.Url.ToString().Replace(Request.RawUrl.ToString(), "")
+ "/Images/" + fileName);
}
else { return (uploadFial); }
}
else
{ return (uploadFial); }
}
catch (Exception e)
{
saveLog( e.InnerException + "stack trace **" + e.StackTrace+"data **" +e.Data.ToString());
throw e;
}
}
<form action="~/Home/UploadJson/" id="form6" enctype="multipart/form-data" data_ajax="false" method="post">
<input type="file" name="file" />
<input type="submit" value="upload file ready" />
</form>
我也在网络配置服务器中设置:
<httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
但无法从 Android 浏览器上传文件到 IIS 服务器。
【问题讨论】:
-
给我们更多信息。描述错误。
标签: asp.net-mvc file-upload iis-7 android-browser