internal static WebRequest CreateRequest(Uri uri) { // Ideally we would want to use RegisterPrefix and WebRequest.Create. // However, these two functions regress 700k working set in System.dll and System.xml.dll // which is mostly for logging and config. // Call PackWebRequestFactory.CreateWebRequest to bypass the regression if possible // by calling Create on PackWebRequest if uri is pack scheme if (string.Compare(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.Ordinal) == 0) { return(PackWebRequestFactory.CreateWebRequest(uri)); // The PackWebRequest may end up creating a "real" web request as its inner request. // It will then call this method again. } // Work around the issue with FileWebRequest not handling #. // FileWebRequest doesn't support the concept of query and fragment. if (uri.IsFile) { uri = new Uri(uri.GetLeftPart(UriPartial.Path)); } WebRequest request = WebRequest.Create(uri); // It is not clear whether WebRequest.Create() can ever return null, but v1 code make this check in // a couple of places, so it is still done here, just in case. if (request == null) { // Unfortunately, there is no appropriate exception string in PresentationCore, and for v3.5 // we have a total resource freeze. So just report WebExceptionStatus.RequestCanceled: // "The request was canceled, the WebRequest.Abort method was called, or an unclassifiable error // occurred. This is the default value for Status." Uri requestUri = BaseUriHelper.PackAppBaseUri.MakeRelativeUri(uri); throw new WebException(requestUri.ToString(), WebExceptionStatus.RequestCanceled); //throw new IOException(SR.Get(SRID.GetResponseFailed, requestUri.ToString())); } HttpWebRequest httpRequest = request as HttpWebRequest; if (httpRequest != null) { if (string.IsNullOrEmpty(httpRequest.UserAgent)) { httpRequest.UserAgent = DefaultUserAgent; } CookieHandler.HandleWebRequest(httpRequest); if (String.IsNullOrEmpty(httpRequest.Referer)) { httpRequest.Referer = BindUriHelper.GetReferer(uri); } CustomCredentialPolicy.EnsureCustomCredentialPolicy(); // Enable NTLM authentication. // This is safe to do thanks to the CustomCredentialPolicy. httpRequest.UseDefaultCredentials = true; } return(request); }