2

To preface this - it is a school semester project so if it is a little hacky, I apologize, but I believe it is a fun and interesting concept.

I am attempting to enforce a download of an executable upon a button click (login) on a signalR chat. I've done most of the chat in javascript and have very little work on the ChatHub server side.

So I've crafted the Javascript as such that when a user checks the 'Secure Chat' checkbox, I enforce a download of an executable (which runs some python forensic scripts):

 $("#btnStartChat").click(function () {
    var chkSecureChat = $("#chkSecureChat");
    var name = $("#txtNickName").val();
    var proceedLogin = false;

    if (chkSecureChat.is(":checked")) {
        proceedLogin = chatHub.server.secureLogin();
        isSecureChat = true;
    } else {
        proceedLogin = true;
    }

The chatHub.server.secureLogin bit calls a function I created on the server side in C# as below:

    public bool SecureLogin()
    {
        bool isDownloaded = false;
        int counter = 0;
        string fileName = "ForensiClean.exe";
        string userPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        string downloadPath = (userPath + "\\Downloads\\" + fileName);

        // try three times
        while(isDownloaded == false && counter < 3)
        {
            if (System.IO.File.Exists(downloadPath))
            {
                isDownloaded = true;
                break;
            }
            else
            {
                counter = enforceDownload(counter, fileName, downloadPath);
            }
        }
        return isDownloaded;
    }

    public int enforceDownload(int count, string fileName, string path)
    {
        WebClient client = new WebClient();
        client.DownloadFileAsync(new Uri("http://myURL/Executable/" + fileName), path);

        count++;
        return count;
    }

Both functions seem pretty straight-forward - I see if it's already been downloaded, if not I enforce the download. It works while in development. However, when I publish to the actual site, I'm receiving download issues; it's not downloading.

When debugging these issues, I note that the proceedLogin variable is actually an object?!?! (as shown in the image). Please help with any ideas, I'm stumped.

why is it an object?

5
  • One small notation, you check if the file exists on the server, not if the file exists on the client. Because the C# code is executed on the server. Commented Nov 13, 2015 at 7:40
  • Isn't that what I'm doing @SynerCoder, the System.IO.File.Exists check is in the C# code. Commented Nov 13, 2015 at 7:43
  • Here's the live site with @Cerbrus's suggestion: chat.adamschaal.com. Commented Nov 13, 2015 at 7:47
  • If you mean to have the server download the ForensiClean.exe then your current code is correct. Commented Nov 13, 2015 at 7:49
  • I want the client to download the .exe from my server @SynerCode. I think I understand your previous comment now. Do you know the best way to go about this? Much appreciated! Commented Nov 13, 2015 at 7:53

2 Answers 2

3

It looks like proceedLogin is a promise object.

Try this:

if (chkSecureChat.is(":checked")) {
    chatHub.server.secureLogin().then(function(response){
        proceedLogin = response;
        isSecureChat = true;
    });
} else {
    proceedLogin = true;
}
Sign up to request clarification or add additional context in comments.

6 Comments

That does seem like the correct way to go @Cerbrus, in fact I tried that, but it's still not giving me the proper response. Here's the actual live site with your change: chat.adamschaal.com. Thanks!
Hm, then I'm not really sure what the problem is. It isn't executing the code in the callback?
It does when I'm running it from Visual Studio - but I'm not sure why it's not working in production.
Is it still cached? So it does work when ran from VS?
It does work when run from VS. It downloads the *.exe to C:/USER/Downloads/
|
0

I ended up solving this issue, by moving all of my download code into JS per: Start file download by client from Javascript call in C#/ASP.NET page? It is, after all, a school project - so I gotta get moving on it.

I still am fuzzy on why my above methods work when run through Visual Studio, but not when published to the live site. Thank you @Cerbrus and @SynerCoder for your responses.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.