Search code examples
c#phpmysqlchromium-embeddedcefsharp

Passing data from a javascript function in my remote website to a c# application on my desktop application


I have a dynamic program. These are the steps that the program follows.

i) I have a windows form application and I have divided the window into two parts. One part contains a ChromiumWebBrowser where it loads a remote website (like www.abc.com). The other part does normal operations of fetching data from a wampserver MYSQL DATABASE installed on the local computer and gives output on the same window division.

ii) Now I use the Chromium web browser to import data from the remote website and send it to a local php file in the local wampserver and then inside the php file I send the data to appropriate local database tables.

iii) When the remote website loads, there is a button "Import data" and then this importation is processed via an AJAX call and now it is in the ajax success: function(){ } that I send the data to my local php file. (I have control over both remote and local wampservers)

iv) NOW MY QUESTION IS how do I pass the data from the external javascript ajax to my c# application so that I don't need to have the local php file i.e. The received data will be sent to database directly from c#

v) And are there any security threats in the process?

I hope I'm was clear, Any suggestions are welcome


Solution

  • Easiest option is to implement a custom scheme. So for example you would make your requests to custom://ajax/uploadToDatabase. You can then parse the request, update the database and respond accordingly.

    http://rawgit.com/cefsharp/CefSharp/master/CefSharp.Example/Resources/Home.html#features-custom-schemes

    https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.Example/CefSharpSchemeHandler.cs#L51

    The CefSharp.WinForms.Example and CefSharp.Wpf.Example projects both provide a working implementation. They're available on GitHub

    https://github.com/cefsharp/CefSharp