Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / HttpCookieCollection.cs / 1 / HttpCookieCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* Collection of Http cookies for request and response intrinsics
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web {
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Web.Util;
///
///
/// Provides a type-safe
/// way to manipulate HTTP cookies.
///
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpCookieCollection : NameObjectCollectionBase {
// Response object to notify about changes in collection
private HttpResponse _response;
// cached All[] arrays
private HttpCookie[] _all;
private String[] _allKeys;
private bool _changed;
internal HttpCookieCollection(HttpResponse response, bool readOnly)
: base(StringComparer.OrdinalIgnoreCase) {
_response = response;
IsReadOnly = readOnly;
}
///
///
/// Initializes a new instance of the HttpCookieCollection
/// class.
///
///
public HttpCookieCollection(): base(StringComparer.OrdinalIgnoreCase) {
}
internal bool Changed {
get { return _changed; }
set { _changed = value; }
}
internal void AddCookie(HttpCookie cookie, bool append) {
_all = null;
_allKeys = null;
if (append) {
// mark cookie as new
cookie.Added = true;
BaseAdd(cookie.Name, cookie);
}
else {
if (BaseGet(cookie.Name) != null) {
// mark the cookie as changed because we are overriding the existing one
cookie.Changed = true;
}
BaseSet(cookie.Name, cookie);
}
}
internal void RemoveCookie(String name) {
_all = null;
_allKeys = null;
BaseRemove(name);
_changed = true;
}
internal void Reset() {
_all = null;
_allKeys = null;
BaseClear();
_changed = true;
}
//
// Public APIs to add / remove
//
///
///
/// Adds a cookie to the collection.
///
///
public void Add(HttpCookie cookie) {
if (_response != null)
_response.BeforeCookieCollectionChange();
AddCookie(cookie, true);
if (_response != null)
_response.OnCookieAdd(cookie);
}
///
/// [To be supplied.]
///
public void CopyTo(Array dest, int index) {
if (_all == null) {
int n = Count;
_all = new HttpCookie[n];
for (int i = 0; i < n; i++)
_all[i] = Get(i);
}
_all.CopyTo(dest, index);
}
///
/// Updates the value of a cookie.
///
public void Set(HttpCookie cookie) {
if (_response != null)
_response.BeforeCookieCollectionChange();
AddCookie(cookie, false);
if (_response != null)
_response.OnCookieCollectionChange();
}
///
///
/// Removes a cookie from the collection.
///
///
public void Remove(String name) {
if (_response != null)
_response.BeforeCookieCollectionChange();
RemoveCookie(name);
if (_response != null)
_response.OnCookieCollectionChange();
}
///
///
/// Clears all cookies from the collection.
///
///
public void Clear() {
Reset();
}
//
// Access by name
//
///
/// Returns an item from the collection.
///
public HttpCookie Get(String name) {
HttpCookie cookie = (HttpCookie)BaseGet(name);
if (cookie == null && _response != null) {
// response cookies are created on demand
cookie = new HttpCookie(name);
AddCookie(cookie, true);
_response.OnCookieAdd(cookie);
}
return cookie;
}
///
/// Indexed value that enables access to a cookie in the collection.
///
public HttpCookie this[String name]
{
get { return Get(name);}
}
//
// Indexed access
//
///
///
/// Returns an
/// item from the collection.
///
///
public HttpCookie Get(int index) {
return(HttpCookie)BaseGet(index);
}
///
///
/// Returns key name from collection.
///
///
public String GetKey(int index) {
return BaseGetKey(index);
}
///
///
/// Default property.
/// Indexed property that enables access to a cookie in the collection.
///
///
public HttpCookie this[int index]
{
get { return Get(index);}
}
//
// Access to keys and values as arrays
//
/*
* All keys
*/
///
///
/// Returns
/// an array of all cookie keys in the cookie collection.
///
///
public String[] AllKeys {
get {
if (_allKeys == null)
_allKeys = BaseGetAllKeys();
return _allKeys;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* Collection of Http cookies for request and response intrinsics
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web {
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Web.Util;
///
///
/// Provides a type-safe
/// way to manipulate HTTP cookies.
///
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpCookieCollection : NameObjectCollectionBase {
// Response object to notify about changes in collection
private HttpResponse _response;
// cached All[] arrays
private HttpCookie[] _all;
private String[] _allKeys;
private bool _changed;
internal HttpCookieCollection(HttpResponse response, bool readOnly)
: base(StringComparer.OrdinalIgnoreCase) {
_response = response;
IsReadOnly = readOnly;
}
///
///
/// Initializes a new instance of the HttpCookieCollection
/// class.
///
///
public HttpCookieCollection(): base(StringComparer.OrdinalIgnoreCase) {
}
internal bool Changed {
get { return _changed; }
set { _changed = value; }
}
internal void AddCookie(HttpCookie cookie, bool append) {
_all = null;
_allKeys = null;
if (append) {
// mark cookie as new
cookie.Added = true;
BaseAdd(cookie.Name, cookie);
}
else {
if (BaseGet(cookie.Name) != null) {
// mark the cookie as changed because we are overriding the existing one
cookie.Changed = true;
}
BaseSet(cookie.Name, cookie);
}
}
internal void RemoveCookie(String name) {
_all = null;
_allKeys = null;
BaseRemove(name);
_changed = true;
}
internal void Reset() {
_all = null;
_allKeys = null;
BaseClear();
_changed = true;
}
//
// Public APIs to add / remove
//
///
///
/// Adds a cookie to the collection.
///
///
public void Add(HttpCookie cookie) {
if (_response != null)
_response.BeforeCookieCollectionChange();
AddCookie(cookie, true);
if (_response != null)
_response.OnCookieAdd(cookie);
}
///
/// [To be supplied.]
///
public void CopyTo(Array dest, int index) {
if (_all == null) {
int n = Count;
_all = new HttpCookie[n];
for (int i = 0; i < n; i++)
_all[i] = Get(i);
}
_all.CopyTo(dest, index);
}
///
/// Updates the value of a cookie.
///
public void Set(HttpCookie cookie) {
if (_response != null)
_response.BeforeCookieCollectionChange();
AddCookie(cookie, false);
if (_response != null)
_response.OnCookieCollectionChange();
}
///
///
/// Removes a cookie from the collection.
///
///
public void Remove(String name) {
if (_response != null)
_response.BeforeCookieCollectionChange();
RemoveCookie(name);
if (_response != null)
_response.OnCookieCollectionChange();
}
///
///
/// Clears all cookies from the collection.
///
///
public void Clear() {
Reset();
}
//
// Access by name
//
///
/// Returns an item from the collection.
///
public HttpCookie Get(String name) {
HttpCookie cookie = (HttpCookie)BaseGet(name);
if (cookie == null && _response != null) {
// response cookies are created on demand
cookie = new HttpCookie(name);
AddCookie(cookie, true);
_response.OnCookieAdd(cookie);
}
return cookie;
}
///
/// Indexed value that enables access to a cookie in the collection.
///
public HttpCookie this[String name]
{
get { return Get(name);}
}
//
// Indexed access
//
///
///
/// Returns an
/// item from the collection.
///
///
public HttpCookie Get(int index) {
return(HttpCookie)BaseGet(index);
}
///
///
/// Returns key name from collection.
///
///
public String GetKey(int index) {
return BaseGetKey(index);
}
///
///
/// Default property.
/// Indexed property that enables access to a cookie in the collection.
///
///
public HttpCookie this[int index]
{
get { return Get(index);}
}
//
// Access to keys and values as arrays
//
/*
* All keys
*/
///
///
/// Returns
/// an array of all cookie keys in the cookie collection.
///
///
public String[] AllKeys {
get {
if (_allKeys == null)
_allKeys = BaseGetAllKeys();
return _allKeys;
}
}
}
}
// 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
- Triangle.cs
- ArgumentException.cs
- Content.cs
- DataGridBeginningEditEventArgs.cs
- XPathDescendantIterator.cs
- AttributeTableBuilder.cs
- MouseWheelEventArgs.cs
- NativeMethods.cs
- EdmConstants.cs
- FormClosingEvent.cs
- BrushConverter.cs
- WrapPanel.cs
- CodeNamespaceCollection.cs
- EntityFrameworkVersions.cs
- QueryConverter.cs
- BuilderPropertyEntry.cs
- LicenseException.cs
- TextTreeRootNode.cs
- ProviderConnectionPoint.cs
- brushes.cs
- TextElementEnumerator.cs
- CommandValueSerializer.cs
- formatstringdialog.cs
- PartitionedStream.cs
- CharEntityEncoderFallback.cs
- SqlInfoMessageEvent.cs
- ProgressBarRenderer.cs
- ItemContainerPattern.cs
- WpfSharedXamlSchemaContext.cs
- ToolBarButtonDesigner.cs
- HttpCapabilitiesSectionHandler.cs
- DataGridRow.cs
- Ref.cs
- AttributeSetAction.cs
- WizardPanel.cs
- ContentElement.cs
- M3DUtil.cs
- CommandHelper.cs
- xml.cs
- StringUtil.cs
- MDIClient.cs
- TrackingMemoryStreamFactory.cs
- XmlDataContract.cs
- SqlWorkflowPersistenceService.cs
- TableParagraph.cs
- CatalogPart.cs
- ViewEventArgs.cs
- ManagedCodeMarkers.cs
- PriorityQueue.cs
- SingleResultAttribute.cs
- NavigationExpr.cs
- Win32KeyboardDevice.cs
- BuildResultCache.cs
- TemplateBuilder.cs
- PnrpPermission.cs
- ObsoleteAttribute.cs
- DeflateStream.cs
- UserPreferenceChangedEventArgs.cs
- CustomAttribute.cs
- SystemGatewayIPAddressInformation.cs
- ToolStripContainer.cs
- ControlPaint.cs
- DataRecord.cs
- ContentValidator.cs
- StateChangeEvent.cs
- WpfGeneratedKnownProperties.cs
- NamespaceEmitter.cs
- SqlDelegatedTransaction.cs
- SqlCacheDependencyDatabaseCollection.cs
- NopReturnReader.cs
- NameValueSectionHandler.cs
- GeneratedCodeAttribute.cs
- SerialStream.cs
- BindingOperations.cs
- IListConverters.cs
- SerializationUtility.cs
- InternalDispatchObject.cs
- FrameworkElementAutomationPeer.cs
- NameValueConfigurationElement.cs
- MailHeaderInfo.cs
- CachingHintValidation.cs
- TypedElement.cs
- RangeBase.cs
- SweepDirectionValidation.cs
- LocatorGroup.cs
- ContentControl.cs
- ItemChangedEventArgs.cs
- CompilationLock.cs
- Pair.cs
- TextMetrics.cs
- SafeHandles.cs
- QueryCreatedEventArgs.cs
- StateBag.cs
- Pair.cs
- RangeValueProviderWrapper.cs
- Wizard.cs
- ContainerVisual.cs
- DetailsViewRow.cs
- DataSetViewSchema.cs
- XmlCustomFormatter.cs