我需要从高完整性(管理员)进程调用 IE8 IEGetProtectedModeCookie API 。每当我从 Azure webapp 调用此 API 时,我都会收到ERROR_INVALID_ACCESS。我在许多地方读到高完整性进程无法调用此 API,但在我的情况下,我需要以提升的权限运行 Azure 沙箱。
有什么方法可以从较低级别的完整性过程中调用此 API?对于 Azure 沙盒,我不得不以提升的权限运行我的 webapp。
[DllImport("ieframe.dll", CharSet = CharSet.Unicode, EntryPoint = "IEGetProtectedModeCookie", SetLastError = true)]
public static extern int IEGetProtectedModeCookie(String url, String cookieName, StringBuilder cookieData, ref int size, int flag);
private static string GetProtectedModeIECookieValue(string cookieName)
{
String r = String.Empty;
int iSize = 4096;
StringBuilder sbValue = new StringBuilder(iSize);
Uri reqUri = HttpContext.Current.Request.Url;
string baseUrl = String.Format(@"{0}://{1}", reqUri.Scheme, reqUri.Authority);
int hResult = IEGetProtectedModeCookie(baseUrl, cookieName, sbValue, ref iSize, 0);
if (hResult == 0)
{
string[] parts = sbValue.ToString().Split('=');
r = parts[1];
HttpContext.Current.Response.Write(r);
}
else
{
//HttpContext.Current.Response.Write("Failed to get cookie. HRESULT=0x" + hResult.ToString("x") + "\nLast Win32Error=" + Marshal.GetLastWin32Error().ToString());
}
return r;
}