Ano*_*ous 3 .net-core webview2
给定
http://0.0.0.0:5000并https://0.0.0.0:6000index.htmlhttps://127.0.0.1:6000/index.html结果
http://127.0.0.1:5000/index.html一切正常https://127.0.0.1:6000/index.html我会收到有关不受信任的证书的错误问题
不应触及 Windows 设置,例如将“localhost”证书标记为“msmc”中受信任的证书或生成自签名证书,因为此 WPF 应用程序应该在不同的计算机上运行。
换句话说,一定有比本文描述的更简单的方法。
红隼
公共类Web服务器
{
公共静态任务运行()
{
var 配置 = new ConfigurationBuilder().Build();
var url = 新[]
{
“http://0.0.0.0:7000”,
“https://0.0.0.0:8000”
};
var 环境 = WebHost
.CreateDefaultBuilder(新字符串[0])
.UseConfiguration(配置)
.UseUrls(url)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<WebStartup>();
返回环境.Build().RunAsync();
}
}
公共类 WebStartup
{
公共 IConfiguration 配置 { 获取;}
public WebStartup(IConfiguration配置)
{
配置=配置;
}
公共无效ConfigureServices(IServiceCollection服务)
{
services.AddSpaStaticFiles(配置=>
{
配置.RootPath =“index.html”;
});
}
公共无效配置(IApplicationBuilder 应用程序,IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
//app.UseHsts();
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
}
}
WPF 中的 WebView2 控件
公共主窗口()
{
WebServer.Run();
初始化组件();
WebView.Source = new Uri("https://127.0.0.1:6000/index.html"); // HTTP 在 5000 上有效,HTTPS 6000 - 不行
WebView.NavigationCompleted +=(对象发送者,CoreWebView2NavigationCompletedEventArgs args)=>
{
WebView.InvalidateVisual();
};
}
WebView2 目前不直接公开该功能。如果您愿意,可以在WebView2 反馈中提出问题,我们可以提出功能请求。
作为解决方法,您可以尝试使用CoreWebView2.CallDevToolsProtocolMethodAsync 方法来调用Security.setIgnoreCertificateErrors DevTools Protocol 方法。但是,我还没有尝试过 setIgnoreCertificateErrors ,并且它也标记为实验性的,因此不能肯定它会按照您想要的方式工作。
| 归档时间: |
|
| 查看次数: |
2417 次 |
| 最近记录: |