- Code: Select all
private void startAsync()
{
Cef.UIThreadTaskFactory.StartNew(delegate
{
try
{
// Create a new RequestContext for the new form
RequestContext requestContext = new RequestContext();
// Create a dictionary to store the proxy settings
var proxySettings = new Dictionary<string, object>();
proxySettings["mode"] = "fixed_servers";
proxySettings["server"] = "*proxy*";
string error;
bool success = requestContext.SetPreference("proxy", proxySettings, out error);
if (!success)
{
Console.WriteLine("Failed to set proxy preference: " + error);
}
success = requestContext.SetPreference("host-resolver-rules", "MAP ripe.net 127.0.0.1:8080", out error);
if (!success)
{
Console.WriteLine("Failed to set host-resolver-rules preference: " + error);
}
// Create a new form
Form frm = new Form();
frm.Text = "New Form";
frm.Width = 600;
frm.Height = 400;
ChromiumWebBrowser browser = new ChromiumWebBrowser();
browser.Dock = DockStyle.Fill;
// Assign the RequestContext to the browser
browser.RequestContext = requestContext;
// Load the URL in the browser
browser.Load("http://ripe.net/");
frm.Controls.Add(browser);
frm.Show();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
});
}
Can you please tell me why cef misses my host-resolver-rules parameter? I need to do it exactly when creating a browser. Every time my site will be new. I can create settings only 1 time.
Proxy work