当前位置:网站首页>The website JS in. Net core cefsharp chromium WebBrowser calls the C method in winfrom program
The website JS in. Net core cefsharp chromium WebBrowser calls the C method in winfrom program
2022-04-23 03:16:00 【Pingshan CP3】
background :winform+CefSharp To open browser website development , Fore and aft end separation , Back end webapi, When you need to log in to the website API Submit client mac Address ;
solve : Called when the website logs in winform Medium method , Method to get the client mac Address before requesting webapi; The following shows how to implement in js Invoking background method in middle note :
Background initialization cef when :
// register JS Classes that can be called , After calling ,js In the initialization “ CefSharp.BindObjectAsync('googleBrower');” after , You can call the registration method directly “googleBrower.postTest('admin','11111',callback);”
chromiumWebBrowser1.JavascriptObjectRepository.Register("googleBrower", new ScriptCallbackManager(this), options: BindingOptions.DefaultBinder);
among googleBrowser It's Jean JS A class is called :
public class ScriptCallbackManager
{
Form _form;
public ScriptCallbackManager(Form form)
{
_form = form;
}
public void PostTest(string username, string pwd, IJavascriptCallback javascriptCallback)
{
Task.Factory.StartNew(async () =>
{
using (javascriptCallback)
{
string response = $"Hello,{username}---{pwd}---networkCard:{NetworkCard()}";
await javascriptCallback.ExecuteAsync(response);
}
});
}
// Get network card information
public string NetworkCard()
{
try
{
string MoAddress = string.Empty;
ManagementClass networkAdapter = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection adapterC = networkAdapter.GetInstances();
foreach (ManagementObject m in adapterC)
{
if ((bool)m["IPEnabled"] == true)
{
MoAddress = m["MacAddress"].ToString().Trim();
m.Dispose();
}
}
return MoAddress;
}
catch
{
return string.Empty;
}
}
}
Finally at the front desk JS call :
CefSharp.BindObjectAsync('googleBrower');// Initialize the method class to call
googleBrower.postTest('admin','11111',callback);// Call the relevant method
It should be noted that , Background methods may start with a capital letter , however JS The middle note is changed to lower case when calling. !!
In this way, the foreground information can be passed into the back-end method , There are other operations in the back-end method ;
版权声明
本文为[Pingshan CP3]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627117249.html
边栏推荐
- 软件测试相关知识~
- 2022年度Top9的任务管理系统
- 12.<tag-链表和常考点综合>-lt.234-回文链表
- Student achievement management
- Aspnetcore configuration multi environment log4net configuration file
- be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?
- 为什么BI对企业这么重要?
- Yes Redis using distributed cache in NE6 webapi
- JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
- 可以接收多種數據類型參數——可變參數
猜你喜欢

2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination

Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!

二进制文件版本控制工具选择难?看完这篇你会找到答案

Iotos IOT middle platform is connected to the access control system of isecure center
![[Mysql] LEFT函数 | RIGHT函数](/img/26/82e0f2280de011636c26931a74e749.png)
[Mysql] LEFT函数 | RIGHT函数

Tencent video price rise: earn more than 7.4 billion a year! Pay attention to me to receive Tencent VIP members, and the weekly card is as low as 7 yuan

be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?

Peut recevoir plusieurs paramètres de type de données - paramètres variables

“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享

Top 9 task management system in 2022
随机推荐
Chapter 7 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of modular programming exercises with functions
be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
Use split to solve the "most common words" problem
Impact of AOT and single file release on program performance
This new feature of C 11, I would like to call it the strongest!
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
二进制文件版本控制工具选择难?看完这篇你会找到答案
The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
2022年P气瓶充装培训试题及模拟考试
2022g2 boiler stoker examination question bank and online simulation examination
Test experience data
ASP. Net 6 middleware series - execution sequence
Preview of converting doc and PDF to SWF file
一套组合拳,打造一款 IDEA 护眼方案
7-11 rearrange the linked list (25 points)
The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot
Two methods are used to solve the "maximum palindrome product" problem
It can receive multiple data type parameters - variable parameters