【发布时间】:2015-12-12 17:25:10
【问题描述】:
我正在开发一个将文件上传到网络服务器 IIS 的 Windows 应用程序。当我在 64 位机器上运行应用程序时,我的代码运行良好。上传到 IIS 工作正常。但是当我在 32 位机器上运行它时,上传不起作用。
我认为这与 IIS 有关。但我不知道它可能是什么。有人遇到过同样的问题吗?
更新:这与服务器端无关。我测试了几个端点,但没有任何效果。
这一定与我的上传代码有关。此代码适用于 64 位应用程序,但不适用于 32 位:
try
{
System.Net.Http.HttpClient hc = new System.Net.Http.HttpClient();
hc.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml");
hc.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
hc.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
hc.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
using (VirtualStream ms = new VirtualStream() { Size = UploadSize })
{
StreamContent content = new StreamContent(ms, BufferSize);
// time for the calculation of the total average throughput
var overallStart = DateTime.Now;
var start = DateTime.Now;
var responseTask = hc.PostAsync(URL, content);
while (!responseTask.IsCompleted)
{
// Check the Exit and Abort Constraints
if ((DateTime.Now - overallStart).TotalMilliseconds > MaxTestLength || _cancelationRequested)
{
System.Diagnostics.Debug.WriteLine("Bytes sent " + bytesSent);
hc.CancelPendingRequests();
IsRunning = false;
return;
}
try
{
bytesSent = ms.Position - bytesOfCalibrationPhase;
}
catch (Exception)
{
// The Upload is an async process which dispses the underlying stream when the upload finishes
// In some cases this could lead to ObjectDiposed Exceptions when accessing the current stream position
// If it is the case, the upload has finished....
break;
}
}
BytesSent 在 32 位机器上始终为“0”...这是为什么呢?
【问题讨论】:
-
"the upload is not working"是什么意思?上传时是否出现错误?它会默默地失败吗?详细说明。 -
它只是默默地失败了。完全没有错误...
-
看看 IIS 中的应用程序池,你有没有将
Enable 32-Bit Applications设置为true?您使用的是哪种托管管道模式? -
@DGibbs 感谢提示,它被设置为 false。我将其设置为 true,但它仍然无法正常工作...我正在使用集成管道...
-
@davidOhara。事件查看器也没有错误?
标签: c# iis upload windows-runtime windows-applications