Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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());
        }
    }
}
Posted
Comments
Sergey Alexandrovich Kryukov 18-Sep-14 12:58pm    
Who knows what happens on your server side? This is just the client part, it does not tell us much.
One practical advice: use jQuery.Ajax(), and other jQuery methods and plug-ins. jQuery is an extremely convenient Javascript library.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900