与えられた
- WPF アプリが Kestrel サーバーを起動します
- ケストレルは耳を傾け
http://0.0.0.0:5000、https://0.0.0.0:6000 - Kestrel は静的 HTML ファイルを指しています
index.html - WPF は、指しているブラウザー コントロール WebView2 を示しています。
https://127.0.0.1:6000/index.html
結果
- WebView2 が
http://127.0.0.1:5000/index.htmlすべて正常に動作するように指定されている場合 - WebView2 が指されている場合
https://127.0.0.1:6000/index.html、信頼されていない証明書に関するエラーが表示されます
質問
- Kestrel または WebView2 で localhost の SSL 検証を無効にするか無視することは可能ですか?
Windows の設定は変更しないでください。たとえば、"msmc" で "localhost" 証明書を信頼済みとしてマークしたり、自己署名証明書を生成したりします。
つまり、この記事で説明したよりも簡単な方法があるはずです。
チョウゲンボウ
パブリック クラス WebServer
{
public static Task Run()
{
var configuration = new ConfigurationBuilder().Build();
変数の 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
{
public IConfiguration 構成 { get; }
パブリック WebStartup (IConfiguration 構成)
{
構成 = 構成;
}
public void ConfigureServices(IServiceCollection サービス)
{
services.AddSpaStaticFiles(構成 =>
{
configuration.RootPath = "index.html";
});
}
public void Configure(IApplicationBuilder アプリ、IWebHostEnvironment 環境)
{
app.UseDeveloperExceptionPage();
//app.UseHsts();
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
}
}
WPF の WebView2 コントロール
public MainWindow()
{
WebServer.Run();
InitializeComponent();
WebView.Source = new Uri("https://127.0.0.1:6000/index.html"); // HTTP は 5000 で動作し、HTTPS 6000 では動作しません - いいえ
WebView.NavigationCompleted += (オブジェクト送信者、CoreWebView2NavigationCompletedEventArgs args) =>
{
WebView.InvalidateVisual();
};
}