当前位置:网站首页>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
边栏推荐
- [mock data] fastmock dynamically returns the mock content according to the incoming parameters
- Experiment 6 input / output stream
- C introduction of variable parameter params
- 建立与遍历二叉树
- Course design of Database Principle -- material distribution management system
- 2022g2 boiler stoker examination question bank and online simulation examination
- Using stack to solve the problem of "mini parser"
- Configure automatic implementation of curd projects
- LoadRunner - performance testing tool
- If the deep replication of objects is realized through C #?
猜你喜欢

The most understandable life cycle of dependency injection

12.<tag-链表和常考点综合>-lt.234-回文链表

The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details

一套组合拳,打造一款 IDEA 护眼方案

《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案

为什么BI对企业这么重要?

A comprehensive understanding of static code analysis

搭建XAMPP时mysql端口被占用

Iotos IOT middle platform is connected to the access control system of isecure center

Configuration table and page information automatically generate curd operation page
随机推荐
Node configuration environment CMD does not take effect
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
Is it difficult to choose binary version control tools? After reading this article, you will find the answer
ASP. Net 6 middleware series - Custom middleware classes
Chapter 7 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of modular programming exercises with functions
Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
Top 9 task management system in 2022
全新的ORM框架——BeetlSQL介绍
What kind of experience is it to prepare for a month to participate in ACM?
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list
数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
yes. Net future
Flink实时数仓项目—DWS层设计与实现
JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
It can receive multiple data type parameters - variable parameters
月薪10k-20k都无法回答的事务问题,你会吗?
ASP. Net 6 middleware series - execution sequence
Maui initial experience: Cool