那可能吗 ? GeckoFX可以使用每个实例单独的CookieContainer? [英] Is that possible ? GeckoFX can use seperate CookieContainer per instance?
问题描述
我用 Geckfx22.0
和 xulrunner22.0
。由于GeckoWebBrowser在.NET中使用GeckoWebBrowsers我想了GeckoWebBrowser的所有其他实例股饼干有它自己的cookie容器不共享以前在其他GeckoWebBrowsers或其他情况下产生的任何cookie。
I'm Using Geckfx22.0
and xulrunner22.0
. Since GeckoWebBrowser in .Net shares cookies with all other instances of GeckoWebBrowsers I would like for a GeckoWebBrowser to have it's own cookie container which doesn't share any cookies that was created previously in other GeckoWebBrowsers or other instances.
例如当我创建一个GeckoWebBrowser它不应该有任何的cookie。而当我运行GeckoWebBrowser 2情况下,他们有自己的cookie容器中,不与对方共享或冲突的cookie。
For example when I create a GeckoWebBrowser it shouldn't have any cookies. And when I run 2 instances of GeckoWebBrowser they have their own cookie container and don't share or conflict cookies with each other.
这怎么可能?
我已经通过创建不同的阶级和启动 geckofx
但尝试了各种可能的方式运行时,它之间共享饼干同一时间不同的浏览器其它浏览器。如果我从一个浏览器中删除的cookie,同样发生了其他浏览器了。我已经启动了代理
和用户代理
在不同的时间和它的作品,但不能同时申请多个浏览器的各种useragents时间。
I've tried various possible ways by creating different class and initiating geckofx
but when running different browser at same time it sharing cookies among other browsers. If i remove cookies from one browser , the same happening for other browsers too. I have initiated the proxy
and useragent
at different times and its works but cant apply various useragents for multiple browsers at the same time.
public void Initiate()
{
Gecko.Xpcom.Initialize(AppDomain.CurrentDomain.BaseDirectory + "/xulrunner");
if (this.IsProxySet)
{
Gecko.GeckoPreferences.User["network.proxy.http"] = this.Host;
Gecko.GeckoPreferences.User["network.proxy.http_port"] = this.Port;
Gecko.GeckoPreferences.User["network.proxy.type"] = 1;
}
if (IsUseragentSet)
{
Gecko.GeckoPreferences.User["general.useragent.override"] = this.Useragent;
}
}
和删除我使用下面的代码的cookie:
And to remove cookies i'm using following code :
nsICookieManager CookieMan;
CookieMan = Xpcom.GetService<nsICookieManager>("@mozilla.org/cookiemanager;1");
CookieMan = Xpcom.QueryInterface<nsICookieManager>(CookieMan);
CookieMan.RemoveAll();
帮助将不胜感激!
Help will be appreciated !!!
推荐答案
您可以尝试有可能实现自己的cookie管理器支持这样的:
You could possibly try implementing your own cookie manager that supports this:
看到单元测试的 Register_AfterDefaultFactoryHasBeenUnregistered_NewCookieServiceIsUsedInsteadOfDefaultOne
对于如何做到这一点的例子。
see unittest Register_AfterDefaultFactoryHasBeenUnregistered_NewCookieServiceIsUsedInsteadOfDefaultOne for an example of how to do this.
此代码是目前未经测试,可能含有typeos
此代码要求一个geckofx版本比新v22.0-0.6
[Guid("c375fa80-150f-11d6-a618-0010a401eb10")]
[ContractID(TestCookieServiceFactory.ContractID)]
public class TestCookieServiceFactory
: GenericOneClassNsFactory<TestCookieServiceFactory, TestCookieService>
{
public const string ContractID = "@mozilla.org/cookieService;1";
}
public class TestCookieService : nsICookieService
{
// Implement nsICookieService...
}
public void Main()
{
Xpcom.Initialize("My Xulrunner/Fireofox location");
var existingFactoryDetails = TestCookieServiceFactory.Unregister();
TestCookieServiceFactory.Register();
var browser = new GeckofxWebBrowser();
// Add browser to form etc...
browser.Navigate("http://SomeWebPageThatUsesCookies")
// Cookie requests should now be sent to TestCookieService, process them as your want.
}
这篇关于那可能吗 ? GeckoFX可以使用每个实例单独的CookieContainer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!