当前位置:网站首页>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
边栏推荐
- Data mining series (3)_ Data mining plug-in for Excel_ Estimation analysis
- Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
- If the deep replication of objects is realized through C #?
- 2022山东省安全员C证上岗证题库及在线模拟考试
- IOTOS物联中台对接海康安防平台(iSecure Center)门禁系统
- Configuration table and page information automatically generate curd operation page
- svg标签中利用<polygon/>循环数组绘制多边形
- Use of metagroup object tuple in C
- LoadRunner - performance testing tool
- Use of slice grammar sugar in C #
猜你喜欢
Why is bi so important to enterprises?
一文了解全面静态代码分析
Aspnetcore configuration multi environment log4net configuration file
[vs Code] solve the problem that the jupyter file displays exceptions in vs code
OLED多级菜单记录
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
Configure automatic implementation of curd projects
Xutils3 corrected a bug I reported. Happy
Ide-idea-problem
ASP. Net 6 middleware series - execution sequence
随机推荐
Top 9 task management system in 2022
Miniapi of. Net7 (special section): NET7 Preview3
2022 P cylinder filling training test questions and simulation test
Use DFS to solve the problem of "number of dictionary rows"
场景题:A系统如何使用B系统的页面
ASP. Net 6 middleware series - execution sequence
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
ThreadLocal 测试多线程变量实例
建立与遍历二叉树
First in the binary tree
搭建XAMPP时mysql端口被占用
[new version release] componentone added Net 6 and blazor platform control support
中后二叉建树
2022年做跨境电商五大技巧小分享
Iotos IOT middle platform is connected to the access control system of isecure center
一文了解全面静态代码分析
Mysql database, inconsistent index character set, slow SQL query, interface timeout
Course design of Database Principle -- material distribution management system
Use of metagroup object tuple in C
12.<tag-链表和常考点综合>-lt.234-回文链表