private void FlashPolicyCallback(IAsyncResult result) { WebRequest wreq = (result.AsyncState as WebRequest); BrowserHttpWebResponse wres = (BrowserHttpWebResponse)wreq.EndGetResponse(result); // we either got a Flash policy or (if none/bad) a NoAccessPolicy, either way we continue... policy = CrossDomainPolicyManager.BuildFlashPolicy(wres); GetResponse(this.Method, uri, true); }
private IAsyncResult GetResponse(string method, Uri uri, bool sendHeaders) { if ((uri.Scheme != "http") && (uri.Scheme != "https")) { async_result.Exception = new SecurityException("Bad scheme"); async_result.SetComplete(); return(async_result); } // this is a same site (site of origin, SOO) request; or // we either already know the policy (previously downloaded); or // we try to download the policy if (!IsDownloadingPolicy()) { policy = CrossDomainPolicyManager.GetCachedWebPolicy(uri); if (policy == null) { // we'll download the policy *then* proceed to the requested URI policy = CrossDomainPolicyManager.PolicyDownloadPolicy; Uri silverlight_policy_uri = CrossDomainPolicyManager.GetSilverlightPolicyUri(uri); BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal(null, silverlight_policy_uri); return(preq.BeginGetResponse(new AsyncCallback(SilverlightPolicyCallback), preq)); } } // Console.WriteLine ("{0} '{1}' using policy: {2}", method, uri, policy); HttpWebRequest wreq = GetHttpWebRequest(uri); wreq.Method = method; // store exception, to throw later, if we have no policy or are not allowed by the policy #if !ANDROID_HACK if ((policy == null) || !policy.IsAllowed(wreq)) { if ((policy == null) || (policy.Exception == null)) { async_result.Exception = new SecurityException(); } else { async_result.Exception = policy.Exception; } async_result.SetComplete(); return(async_result); } #endif if (!sendHeaders) { wreq.Headers.Clear(); } wreq.progress = progress; return(wreq.BeginGetResponse(new AsyncCallback(EndCallback), wreq)); }
private void SilverlightPolicyCallback(IAsyncResult result) { WebRequest wreq = (result.AsyncState as WebRequest); BrowserHttpWebResponse wres = (BrowserHttpWebResponse)wreq.EndGetResponse(result); policy = CrossDomainPolicyManager.BuildSilverlightPolicy(wres); if (policy != null) { // we got our policy so we can proceed with the main request GetResponse(this.Method, uri, true); } else { // no policy but we get a second chance to try a Flash policy Uri flash_policy_uri = CrossDomainPolicyManager.GetFlashPolicyUri(wres.ResponseUri); BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal(null, flash_policy_uri); preq.BeginGetResponse(new AsyncCallback(FlashPolicyCallback), preq); } }
void ConnectCallback() { SocketError error = SocketError.AccessDenied; try { #if MOONLIGHT || NET_4_0 // Connect to the first address that match the host name, like: // http://blogs.msdn.com/ncl/archive/2009/07/20/new-ncl-features-in-net-4-0-beta-2.aspx // while skipping entries that do not match the address family DnsEndPoint dep = (RemoteEndPoint as DnsEndPoint); if (dep != null) { IPAddress[] addresses = Dns.GetHostAddresses(dep.Host); IPEndPoint endpoint; #if MOONLIGHT && !INSIDE_SYSTEM if (!PolicyRestricted && !SecurityManager.HasElevatedPermissions) { List <IPAddress> valid = new List <IPAddress> (); foreach (IPAddress a in addresses) { // if we're not downloading a socket policy then check the policy // and if we're not running with elevated permissions (SL4 OoB option) endpoint = new IPEndPoint(a, dep.Port); if (!CrossDomainPolicyManager.CheckEndPoint(endpoint, policy_protocol)) { continue; } valid.Add(a); } addresses = valid.ToArray(); } #endif foreach (IPAddress addr in addresses) { try { if (curSocket.AddressFamily == addr.AddressFamily) { endpoint = new IPEndPoint(addr, dep.Port); error = TryConnect(endpoint); if (error == SocketError.Success) { ConnectByNameError = null; break; } } } catch (SocketException se) { ConnectByNameError = se; error = SocketError.AccessDenied; } } } else { ConnectByNameError = null; #if MOONLIGHT && !INSIDE_SYSTEM if (!PolicyRestricted && !SecurityManager.HasElevatedPermissions) { if (CrossDomainPolicyManager.CheckEndPoint(RemoteEndPoint, policy_protocol)) { error = TryConnect(RemoteEndPoint); } } else #endif error = TryConnect(RemoteEndPoint); } #else error = TryConnect(RemoteEndPoint); #endif } finally { SocketError = error; OnCompleted(this); } }