Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Net / System / Net / _CookieModule.cs / 1 / _CookieModule.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net { internal static class CookieModule { // fields // constructors // properties // methods internal static void OnSendingHeaders(HttpWebRequest httpWebRequest) { GlobalLog.Print("CookieModule::OnSendingHeaders()"); try { if (httpWebRequest.CookieContainer == null) { return; } // // remove all current cookies. This could be a redirect // httpWebRequest.Headers.RemoveInternal(HttpKnownHeaderNames.Cookie); // // add in the new headers from the cookie container for this request // string optCookie2; string cookieString = httpWebRequest.CookieContainer.GetCookieHeader( httpWebRequest.Address, out optCookie2); if (cookieString.Length > 0) { GlobalLog.Print("CookieModule::OnSendingHeaders() setting Cookie header to:[" + cookieString + "]"); httpWebRequest.Headers[HttpKnownHeaderNames.Cookie] = cookieString; //< } } catch { } } internal static void OnReceivedHeaders(HttpWebRequest httpWebRequest) { GlobalLog.Print("CookieModule.OnReceivedHeaders()"); // // if the app doesn't want us to handle cookies then there's nothing // to do. Note that we're leaving open the possibility that these // settings could be changed between the request being made and the // response received // try { if (httpWebRequest.CookieContainer == null) { return; } // // add any received cookies for this response to the container // HttpWebResponse response = httpWebRequest._HttpResponse as HttpWebResponse; if (response == null) { return; } CookieCollection cookies = null; try { string cookieString = response.Headers.SetCookie; GlobalLog.Print("CookieModule::OnSendingHeaders() received Set-Cookie:[" + cookieString + "]"); if ((cookieString != null) && (cookieString.Length > 0)) { cookies = httpWebRequest.CookieContainer.CookieCutter( response.ResponseUri, HttpKnownHeaderNames.SetCookie, cookieString, false); } } catch { } try { string cookieString = response.Headers.SetCookie2; GlobalLog.Print("CookieModule::OnSendingHeaders() received Set-Cookie2:[" + cookieString + "]"); if ((cookieString != null) && (cookieString.Length > 0)) { CookieCollection cookies2 = httpWebRequest.CookieContainer.CookieCutter( response.ResponseUri, HttpKnownHeaderNames.SetCookie2, cookieString, false); if (cookies != null && cookies.Count != 0) { cookies.Add(cookies2); } else { cookies = cookies2; } } } catch { } if (cookies != null) { response.Cookies = cookies; } } catch { } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net { internal static class CookieModule { // fields // constructors // properties // methods internal static void OnSendingHeaders(HttpWebRequest httpWebRequest) { GlobalLog.Print("CookieModule::OnSendingHeaders()"); try { if (httpWebRequest.CookieContainer == null) { return; } // // remove all current cookies. This could be a redirect // httpWebRequest.Headers.RemoveInternal(HttpKnownHeaderNames.Cookie); // // add in the new headers from the cookie container for this request // string optCookie2; string cookieString = httpWebRequest.CookieContainer.GetCookieHeader( httpWebRequest.Address, out optCookie2); if (cookieString.Length > 0) { GlobalLog.Print("CookieModule::OnSendingHeaders() setting Cookie header to:[" + cookieString + "]"); httpWebRequest.Headers[HttpKnownHeaderNames.Cookie] = cookieString; //< } } catch { } } internal static void OnReceivedHeaders(HttpWebRequest httpWebRequest) { GlobalLog.Print("CookieModule.OnReceivedHeaders()"); // // if the app doesn't want us to handle cookies then there's nothing // to do. Note that we're leaving open the possibility that these // settings could be changed between the request being made and the // response received // try { if (httpWebRequest.CookieContainer == null) { return; } // // add any received cookies for this response to the container // HttpWebResponse response = httpWebRequest._HttpResponse as HttpWebResponse; if (response == null) { return; } CookieCollection cookies = null; try { string cookieString = response.Headers.SetCookie; GlobalLog.Print("CookieModule::OnSendingHeaders() received Set-Cookie:[" + cookieString + "]"); if ((cookieString != null) && (cookieString.Length > 0)) { cookies = httpWebRequest.CookieContainer.CookieCutter( response.ResponseUri, HttpKnownHeaderNames.SetCookie, cookieString, false); } } catch { } try { string cookieString = response.Headers.SetCookie2; GlobalLog.Print("CookieModule::OnSendingHeaders() received Set-Cookie2:[" + cookieString + "]"); if ((cookieString != null) && (cookieString.Length > 0)) { CookieCollection cookies2 = httpWebRequest.CookieContainer.CookieCutter( response.ResponseUri, HttpKnownHeaderNames.SetCookie2, cookieString, false); if (cookies != null && cookies.Count != 0) { cookies.Add(cookies2); } else { cookies = cookies2; } } } catch { } if (cookies != null) { response.Cookies = cookies; } } catch { } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListManagerBindingsCollection.cs
- ServiceRoute.cs
- CompoundFileDeflateTransform.cs
- DbDataReader.cs
- ResXResourceReader.cs
- SystemInfo.cs
- InitializationEventAttribute.cs
- WorkflowQueuingService.cs
- QueryOutputWriter.cs
- DrawListViewItemEventArgs.cs
- DataGridCell.cs
- AssemblyNameProxy.cs
- SrgsRuleRef.cs
- FamilyMapCollection.cs
- recordstatescratchpad.cs
- FixedSOMLineCollection.cs
- PixelFormatConverter.cs
- FolderLevelBuildProvider.cs
- URLIdentityPermission.cs
- DictionaryEntry.cs
- CodeAttributeArgument.cs
- XmlObjectSerializer.cs
- WebControl.cs
- SafeWaitHandle.cs
- TypeInitializationException.cs
- RawStylusActions.cs
- PanelStyle.cs
- SystemUnicastIPAddressInformation.cs
- CodeTypeMemberCollection.cs
- VectorAnimationUsingKeyFrames.cs
- EmptyEnumerator.cs
- formatstringdialog.cs
- Directory.cs
- PointLight.cs
- XdrBuilder.cs
- HeaderElement.cs
- SqlRemoveConstantOrderBy.cs
- CompilationLock.cs
- PropertyDescriptorCollection.cs
- Crypto.cs
- SecurityTokenProvider.cs
- BamlTreeUpdater.cs
- HeaderUtility.cs
- UnknownBitmapEncoder.cs
- CreateUserWizardStep.cs
- SerializationException.cs
- MediaPlayer.cs
- XmlUtf8RawTextWriter.cs
- BitmapPalettes.cs
- ZipIOExtraField.cs
- DataGridViewMethods.cs
- IsolatedStorageFileStream.cs
- ListenerElementsCollection.cs
- SafeRightsManagementHandle.cs
- ServiceOperationHelpers.cs
- ClosableStream.cs
- SamlNameIdentifierClaimResource.cs
- XsltQilFactory.cs
- FileRegion.cs
- XmlUtilWriter.cs
- Debugger.cs
- RequestCachePolicy.cs
- GridItem.cs
- SmiEventSink_Default.cs
- XmlQueryRuntime.cs
- ListChangedEventArgs.cs
- CqlQuery.cs
- ConsoleKeyInfo.cs
- WpfWebRequestHelper.cs
- XmlAnyElementAttributes.cs
- DriveInfo.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- ConnectionProviderAttribute.cs
- Aggregates.cs
- NetStream.cs
- BlurEffect.cs
- BehaviorEditorPart.cs
- IgnoreFlushAndCloseStream.cs
- MessageDroppedTraceRecord.cs
- WebEvents.cs
- SimpleBitVector32.cs
- SecurityElement.cs
- OperationCanceledException.cs
- XmlAnyElementAttributes.cs
- FixedSOMSemanticBox.cs
- SmtpNetworkElement.cs
- SplashScreenNativeMethods.cs
- Span.cs
- SectionRecord.cs
- TreeViewBindingsEditor.cs
- Figure.cs
- Inflater.cs
- XmlValidatingReaderImpl.cs
- AppDomainCompilerProxy.cs
- HighContrastHelper.cs
- LabelInfo.cs
- ButtonFieldBase.cs
- COM2ColorConverter.cs
- ApplicationFileCodeDomTreeGenerator.cs
- WsdlHelpGeneratorElement.cs