C#:设置CefSharp的一些参数,比如忽略安全证书

 

 

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

 

 

 

本次记录如何设置CefSharp忽略安全证书,以及他的一些其他配置

参考网址

https://peter.sh/experiments/chromium-command-line-switches/

这个网站记录了CefSharp所有可以设置的配置

http://www.codebye.com/cefsharp-help-2-config-manage.html

这个网站记录了如何具体设置,不过第二个网站在刚才测试中好像没能打开,我简单说一下

 

 

具体设置

我在第一个参考网站中找到证书,他有俩个,我不知道哪个起作用,我就都配置了

            //安全证书
            
            settings.CefCommandLineArgs.Add("--ignore-urlfetcher-cert-requests", "1");
            settings.CefCommandLineArgs.Add("--ignore-certificate-errors", "1");

这是flash的配置

 

            //flash
            settings.CefCommandLineArgs.Add("ppapi-flash-path", AppDomain.CurrentDomain.BaseDirectory + "\\Plugins\\pepflash\\pepflashplayer.dll");

 

 

具体放入的位置参考我上篇博客的InitializeCefSharp方法里,我写个Demo

 

        /// <summary>
        /// 解决anycpu不能兼容
        /// </summary>
        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void InitializeCefSharp()
        {
            var settings = new CefSettings();

            // Set BrowserSubProcessPath based on app bitness at runtime
            settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                                   Environment.Is64BitProcess ? "x64" : "x86",
                                                   "CefSharp.BrowserSubprocess.exe");
            //安全证书
            
            settings.CefCommandLineArgs.Add("--ignore-urlfetcher-cert-requests", "1");
            settings.CefCommandLineArgs.Add("--ignore-certificate-errors", "1");
            //settings.CefCommandLineArgs.Add("allow-http-background-page", "1");
            //settings.CefCommandLineArgs.Add("allow-insecure-localhost","1");
            //settings.CefCommandLineArgs.Add("allow-http-screen-", "1");
            
            //settings.CefCommandLineArgs.Add("reduce-security-for-testing", "1");
            
   
            //flash
            settings.CefCommandLineArgs.Add("ppapi-flash-path", AppDomain.CurrentDomain.BaseDirectory + "\\Plugins\\pepflash\\pepflashplayer.dll");

            // Make sure you set performDependencyCheck false
            Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
        }

 

转载于:https://www.cnblogs.com/DawnCHENXI/p/9289020.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用CefSharp时,建议在项目的属性窗口中选择AnyCPU模式,因为CefSharp是基于Chromium的,所以它可以在x86和x64平台上运行,同时也可以在Windows和Linux上运行。如果你选择了AnyCPU模式,那么你需要在你的应用程序中进行一些配置,以确保它能够在x86和x64平台上运行。 首先,你需要在你的应用程序中添加以下代码: ```csharp if (Environment.Is64BitProcess) { CefSettings settings = new CefSettings(); settings.BrowserSubprocessPath = @"x64\CefSharp.BrowserSubprocess.exe"; Cef.Initialize(settings); } else { Cef.Initialize(); } ``` 这段代码将根据你的应用程序是64位还是32位来选择正确的CefSharp.BrowserSubprocess.exe路径。然后,你需要将CefSharp.BrowserSubprocess.exe和libcef.dll文件复制到你的应用程序的输出目录中。这些文件可以在CefSharp NuGet软件包中找到。 最后,你需要在你的应用程序中添加以下代码: ```csharp AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { if (args.Name.StartsWith("CefSharp")) { string assemblyName = args.Name.Split(new char[] { ',' }, 2)[0] + ".dll"; string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", assemblyName); return File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null; } return null; }; ``` 这段代码将允许你的应用程序在加载CefSharp程序集时选择正确的版本,以便在x86和x64平台上运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值