C#アプリケーションでホストされているWebブラウザコントロールのカスタムセキュリティマネージャを作成する必要があります。ホストされているWebBrowserコントロールは、IEのセキュリティとプライバシーの設定とは独立している必要があります。WebブラウザコントロールでIInternetSecurityManagerを使用してIEプライバシー設定をオーバーライドします
問題:IEのプライバシー設定を「高」に設定されている場合、クッキーに依存してウェブサイトがホストされたWebBrowserコントロールでは正しく機能しません(プライバシーの設定は「中」に設定されている場合、サイトが正常に動作します)。
WebBrowserコントロールをホストするwinformは、以下のGetSecurityId、MapUrlToZone、ProcessUrlActionの実装を提供します。 ProcessUrlActionは、ACTIVEX_RUN、SCRIPT_RUNのようなURLアクションに対して組み込みブラウザによって呼び出されます。 Cookie関連のURLアクションが呼び出されることはありません。
ウェブブラウザ制御用のクッキーを有効にする方法はありますか?または、以下のコードに何か問題がありますか?
private void InitBrowserSecurityData()
{
securityID = new byte[MAX_SIZE_SECURITY_ID];
securityID[0] = (byte)'f';
securityID[1] = (byte)'i';
securityID[2] = (byte)'l';
securityID[3] = (byte)'e';
securityID[4] = (byte)':';
securityID[5] = 0;
securityID[6] = 3;
securityID[7] = 0;
securityID[8] = 0;
securityID[9] = 0;
}
//GetSecurityId
int IInternetSecurityManager.GetSecurityId(string pwszUrl, IntPtr pbSecurityId, ref uint pcbSecurityId, ref uint dwReserved)
{
if (pcbSecurityId >= MAX_SIZE_SECURITY_ID)
{
Marshal.Copy(securityID, 0, pbSecurityId, MAX_SIZE_SECURITY_ID);
pcbSecurityId = 9;
return HResults.S_OK;
}
return (int)WinInetErrors.INET_E_DEFAULT_ACTION;
}
//MapUrlToZone
int IInternetSecurityManager.MapUrlToZone(string pwszUrl, out uint pdwZone, uint dwFlags)
{
pdwZone = (uint)tagURLZONE.URLZONE_LOCAL_MACHINE;
return HResults.S_OK;
}
//ProcessUrlAction
int IInternetSecurityManager.ProcessUrlAction(string pwszUrl, uint dwAction, IntPtr pPolicy,
uint cbPolicy, IntPtr pContext, uint cbContext, uint dwFlags, uint dwReserved)
{
URLACTION action = (URLACTION)dwAction;
bool hasUrlPolicy = (cbPolicy >= unchecked((uint)Marshal.SizeOf(typeof(int))));
URLPOLICY urlPolicy = (hasUrlPolicy) ? (URLPOLICY)Marshal.ReadInt32(pPolicy) : URLPOLICY.ALLOW;
bool hasContext = (cbContext >= unchecked((uint)Marshal.SizeOf(typeof(Guid))));
Guid context = (hasContext) ? (Guid)Marshal.PtrToStructure(pContext, typeof(Guid)) : Guid.Empty;
//all URL actions are allowed
if (hasUrlPolicy)
{
urlPolicy = URLPOLICY.ALLOW;
Marshal.WriteInt32(pPolicy, (int)urlPolicy);
return HResults.S_OK;
}
return (int)WinInetErrors.INET_E_DEFAULT_ACTION;
}
私はすでにこれらの質問を見てきましたが、私にとってはうまくいきません。
Security Level for WebBrowser control
Custom IInternetSecurityManager not being called with dialogs
overriding GetSecurityId in IInternetSecurityManager
私は同様の問題があります。あなたの問題は解決できますか? –
申し訳ありません、この遅い返信バーク。 Cookieの動作がIInternetSecurityManagerに決して渡されないように見える... [this](http://www.tech-archive.net/Archive/InetSDK/microsoft.public.inetsdk.programming.webbrowser_ctl/2006-03/)を見てください。 msg00073.html) – CPJoshi