I have built a small web application using html5, javascript and asp.net/c#, which is supposed to upload a file dropped onto a webpage to the server machine's file system.
The file uploads just fine when I access the web page on the server machine. However when I access the web page on a remote machine the upload fails.
I am using XmlHttpRequest to upload the file.
I have examined the http request using TcpTunnelGui and I can see that the request is successfully sent in both cases, although the http headers are slightly different when the request is made on the server machine compared with on a remote machine. However in both cases the output from TcpTunnelGui shows that the request is a POST.
I have also attached the visual studio debugger to the server process. When the request is sent from the server machine the 'Page.IsPostBack' flag is true and 'Request.Files' is not null as expected. However when the same request is sent from a remote machine the 'Page.IsPostBack' flag is unexpectedly false and 'Request.Files' is null.
If I enable application tracing in the 'web.config' then the output in both cases shows that the request is a POST.
Can anyone suggest why the 'Page.IsPostBack' property is false and 'Request.Files' is null when a http POST request is sent from a remote machine?
Here is the code for my XmlHttpRequest:
function uploadFile(audioItem) {
var audioIndex = audioItem.key.split(".")[1];
var form = document.getElementById('AudioForm');
var data = new FormData(form);
data.append("AUDIOFILE", audioItem.file);
data.append("ACTIONSFILE", audioItem.actionsfile);
data.append("XMLNAME", audioItem.xmlname);
data.append("INDEX", audioIndex);
data.append("AUDIONAME", audioItem.audioname);
data.append("ACTIONSNAME", audioItem.actionsname);
var xhr = new XMLHttpRequest();
if (xhr) {
try {
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
updateAudioList(audioItem.key, "UPLOADED");
} else if (xhr.readyState == 4 && xhr.status == 500) {
updateAudioList(audioItem.key, xhr.statusText);
var response = getXhrResponse(xhr);
alert(response);
} else {
updateAudioList(audioItem.key, "UPLOADING");
}
};
xhr.open('POST', "FixFW4.aspx", true);
xhr.setRequestHeader("Content-type", "multipart/form-data");
xhr.setRequestHeader("Content-Length", audioItem.file.size);
xhr.send(data);
} catch (e) {
alert("Cannot connect to server:\n" + e.toString());
}
}
}