生产环境中的HttpPostedFileBase为空,但测试环境中不为空
本文关键字:测试环境 HttpPostedFileBase 为空 生产环境 | 更新日期: 2023-09-27 18:06:54
我有两个环境,直到今天我都认为是完全一样的。(沙盒,生产)
我有一个移动设备,将文件发送到服务器。这在沙箱环境中工作得很好,但是当我在生产环境中运行相同的东西时,该文件为空。我在网上查过了。config和<httpRuntime requestValidationMode="2.0" maxRequestLength="264768888" />
在这两个环境中都设置为以上。我遗漏了什么?有什么不同呢?这是IIS中的一些设置吗?下列代码:
我要测试的文件是64k。
服务器代码
[HttpPost, Url("v3/organizations/{organizationId?}/SyncVideo/")]
public virtual void SyncVideo(HttpPostedFileBase file, Guid? organizationId) {
if (file == null)
throw new HttpBadRequestException("file is missing");
if (organizationId.IsNull()) throw new HttpNotFoundExecption();
if (organizationId != RESTContext.OrganizationId) throw new HttpNotAuthorizedException();
var basePath = RESTContext.Config.VideoPath;
//using (new Impersonator(RESTContext.Config.VideoPathUsername, RESTContext.Config.VideoPathDomain,
// RESTContext.Config.VideoPathPassword)) {
// if (!Directory.Exists(basePath))
// Directory.CreateDirectory(basePath);
// file.SaveAs(basePath + @"'" + file.FileName);
//}
}
客户机代码public void UploadFile(string url, string path) {
Stream stream = null;
HttpClient client = null;
MultipartFormDataContent content = null;
StreamContent streamContent = null;
try {
stream = Platform.FileSystem.ReadStreamFromFile(path);
Platform.Console.WriteLine(stream.Length.ToString());
client = new HttpClient();
content = new MultipartFormDataContent();
foreach (var header in headers)
client.DefaultRequestHeaders.Add(header.Key, header.Value);
streamContent = new StreamContent(stream);
content.Add(streamContent, "file", Path.GetFileName(path));
var message = client.PostAsync(url, content).Result;
if (message.StatusCode != HttpStatusCode.OK) {
Platform.Console.WriteLine(message.ToString());
throw new Exception(message.ToString());
}
} finally {
content.NullSafeDispose();
client.NullSafeDispose();
stream.NullSafeDispose();
streamContent.NullSafeDispose();
}
}
在服务器上安装。net framework 4.5.1修复了这个问题。之前只有4.5个。