Files
ECO2/ArinWarev1/Forms_Basic/Frm_WebManual.vb
LGram16 132ddc6495 "Replace OWIN self-hosting with WebView2 virtual hosting" -m "-
Remove OWIN server implementation (StaticFileServer, Startup)" -m "- Implement
    WebView2 SetVirtualHostNameToFolderMapping in Frm_WebManual" -m "- Remove all
   OWIN NuGet packages from packages.config and .vbproj" -m "- Add comprehensive
   guide document (WEBVIEW2_VIRTUAL_HOSTING.md)" -m "- Mark legacy OWIN files as
   deprecated
2025-12-01 20:55:42 +09:00

89 lines
3.3 KiB
VB.net

Imports System.IO
Imports System.Threading.Tasks
Imports Microsoft.Web.WebView2.Core
Public Class Frm_WebManual
Private Async Sub Frm_WebManual_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
' WebView2 초기화
Await InitializeWebView2Async()
Try
' 가상 호스팅 설정
If WebView21.CoreWebView2 Is Nothing Then
Return
End If
' wwwroot 경로 확인
Dim _wwwrootPath As String = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot")
If String.IsNullOrEmpty(_wwwrootPath) Then
_wwwrootPath = Path.Combine(Application.StartupPath, "wwwroot")
End If
' 디렉토리가 없으면 생성
If Not Directory.Exists(_wwwrootPath) Then
Directory.CreateDirectory(_wwwrootPath)
End If
' 가상 호스트 매핑 설정
' https://eco2.local/ -> 로컬 폴더 매핑
WebView21.CoreWebView2.SetVirtualHostNameToFolderMapping(
"eco2.local",
_wwwrootPath,
CoreWebView2HostResourceAccessKind.Allow)
If WebView21 IsNot Nothing AndAlso WebView21.CoreWebView2 IsNot Nothing Then
' 가상 호스트 URL 사용
Dim url As String = "https://eco2.local/index.html"
WebView21.CoreWebView2.Navigate(url)
End If
Catch ex As Exception
MessageBox.Show("웹페이지 이동 중 오류가 발생했습니다: " & ex.Message,
"오류", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Catch ex As Exception
MessageBox.Show("웹페이지 로드 중 오류가 발생했습니다: " & ex.Message,
"오류", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Async Function InitializeWebView2Async() As Task
Try
' Fixed Version 경로 설정
Dim fixedVersionPath = Path.Combine(Application.StartupPath, "WebView2Runtime")
Dim userDataFolder = Path.Combine(Application.StartupPath, "WebView2Data")
' Fixed Version이 있는지 확인
If Directory.Exists(fixedVersionPath) Then
' Fixed Version 사용
Dim env = Await CoreWebView2Environment.CreateAsync(fixedVersionPath, userDataFolder)
Await WebView21.EnsureCoreWebView2Async(env)
Else
' 시스템에 설치된 Runtime 사용 (폴백)
Await WebView21.EnsureCoreWebView2Async(Nothing)
End If
Catch ex As Exception
' WebView2 Runtime을 찾을 수 없는 경우
MessageBox.Show(
"WebView2 구성 요소를 찾을 수 없습니다." & vbCrLf & vbCrLf &
"프로그램 설치가 올바르지 않을 수 있습니다." & vbCrLf &
"관리자에게 문의하시기 바랍니다.",
"오류",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Me.Close()
End Try
End Function
End Class