在 CefSharp 中保存浏览器数据
Save browser data in CefSharp
我有一个使用 CefSharp 的 Windows 表单应用程序。
前一段时间我使用了一段代码来保存浏览器的状态,例如登录详细信息等,这样用户就不必多次登录。
这是我使用的代码:
private static bool _hasRun;
CefSettings settings = new CefSettings();
if (!_hasRun)
{
Cef.Initialize(new CefSettings { CachePath = "MyCachePath", PersistSessionCookies = true });
}
_hasRun = true;
string cache_dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CEF";
settings.CachePath = cache_dir;
settings.CefCommandLineArgs.Add("persist_session_cookies", "1");
string link = Domain;
chrome = new ChromiumWebBrowser(link);
this.tabPage2.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
此代码在我的旧应用程序中运行良好,但在我最近的应用程序中使用此代码时,我收到此错误消息:
有什么建议吗?
您必须提供完整路径。
non-absolute: "MyCachepath"
absolute: "C:\users\username\documents\MyCachepath"
为什么它在旧项目中有效?
一些项目类型和版本会自动将相对路径转换为绝对路径,如下所示:
environment.CurrentDirectory + @"\MyCachepath"
我有一个使用 CefSharp 的 Windows 表单应用程序。 前一段时间我使用了一段代码来保存浏览器的状态,例如登录详细信息等,这样用户就不必多次登录。
这是我使用的代码:
private static bool _hasRun;
CefSettings settings = new CefSettings();
if (!_hasRun)
{
Cef.Initialize(new CefSettings { CachePath = "MyCachePath", PersistSessionCookies = true });
}
_hasRun = true;
string cache_dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CEF";
settings.CachePath = cache_dir;
settings.CefCommandLineArgs.Add("persist_session_cookies", "1");
string link = Domain;
chrome = new ChromiumWebBrowser(link);
this.tabPage2.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
此代码在我的旧应用程序中运行良好,但在我最近的应用程序中使用此代码时,我收到此错误消息:
有什么建议吗?
您必须提供完整路径。
non-absolute: "MyCachepath"
absolute: "C:\users\username\documents\MyCachepath"
为什么它在旧项目中有效?
一些项目类型和版本会自动将相对路径转换为绝对路径,如下所示:
environment.CurrentDirectory + @"\MyCachepath"