Reputation: 2908
I've setup my project and code according to the guides for loading files from the local file system (Referenced site). The web files are all right there in the project. Even though the two properties are set to enable FileAccessFromFileUrls
and UniversalAccessFromFileUrls
, the content in the browser control is still empty and the debugger indicates 'Not allowed to load local resource'. Cannot see the reason why CefSharp won't load the file.
Using version 63.0.3.0
public Form1()
{
InitializeComponent();
InitializeChromium();
Controls.Add(_chromiumWebBrowser);
}
private void InitializeChromium()
{
var settings = new CefSettings();
Cef.Initialize(settings);
var address = $@"{Application.StartupPath}\HtmlResources\html\index.html";
_chromiumWebBrowser = new ChromiumWebBrowser(address);
_chromiumWebBrowser.Dock = DockStyle.Fill;
_chromiumWebBrowser.IsBrowserInitializedChanged += OnBrowserInitialized;
_chromiumWebBrowser.FrameLoadEnd += OnFrameLoadEnd;
_jsToSharp = new JsToSharp(_chromiumWebBrowser);
_chromiumWebBrowser.JavascriptObjectRepository.Register("jsToSharp", _jsToSharp, true);
var browserSettings = new BrowserSettings
{
FileAccessFromFileUrls = CefState.Enabled,
UniversalAccessFromFileUrls = CefState.Enabled
};
_chromiumWebBrowser.BrowserSettings = browserSettings;
}
Upvotes: 2
Views: 4005
Reputation: 18980
Check all your html, js, etc files getting copied to the build output directory in the project settings of Visual Studio. In the "Build Action" properties set 'Copy to Output' = 'Copy if newer'.
Upvotes: 3