Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / Profile / ProfileModule.cs / 1 / ProfileModule.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* ProfileModule class
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Profile {
using System.Web;
using System.Text;
using System.Web.Compilation;
using System.Web.Configuration;
using System.Web.Caching;
using System.Collections;
using System.Web.Util;
using System.Security.Principal;
using System.Security.Permissions;
using System.Reflection;
using System.Web.Security;
using System.Globalization;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Configuration;
#if !FEATURE_PAL
using System.Web.DataAccess;
#endif // !FEATURE_PAL
///
/// [To be supplied.]
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ProfileModule : IHttpModule
{
private static object s_Lock = new object();
private ProfileEventHandler _eventHandler = null;
private ProfileMigrateEventHandler _MigrateEventHandler;
private ProfileAutoSaveEventHandler _AutoSaveEventHandler;
///
///
/// Initializes a new instance of the
/// class.
///
///
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
public ProfileModule()
{
}
///
/// This is a Global.asax event which must be
/// named FormsAuthorize_OnAuthorize event. It's used by advanced users to
/// customize cookie authentication.
///
public event ProfileEventHandler Personalize
{
add { _eventHandler += value; }
remove { _eventHandler -= value; }
}
public event ProfileMigrateEventHandler MigrateAnonymous
{
add { _MigrateEventHandler += value; }
remove { _MigrateEventHandler -= value; }
}
public event ProfileAutoSaveEventHandler ProfileAutoSaving {
add { _AutoSaveEventHandler += value; }
remove { _AutoSaveEventHandler -= value; }
}
///
/// [To be supplied.]
///
public void Dispose()
{
}
///
/// [To be supplied.]
///
public void Init(HttpApplication app)
{
if (ProfileManager.Enabled) {
app.AcquireRequestState += new EventHandler(this.OnEnter);
if (ProfileManager.AutomaticSaveEnabled) {
app.EndRequest += new EventHandler(this.OnLeave);
}
}
}
private void OnPersonalize(ProfileEventArgs e)
{
if (_eventHandler != null)
_eventHandler(this, e);
if (e.Profile != null)
{
e.Context._Profile = e.Profile;
return;
}
e.Context._ProfileDelayLoad = true;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
///
/// [To be supplied.]
///
private void OnEnter(Object source, EventArgs eventArgs)
{
HttpContext context = ((HttpApplication)source).Context;
OnPersonalize(new ProfileEventArgs(context));
if (context.Request.IsAuthenticated && !string.IsNullOrEmpty(context.Request.AnonymousID) && _MigrateEventHandler != null)
{
ProfileMigrateEventArgs e = new ProfileMigrateEventArgs(context, context.Request.AnonymousID);
_MigrateEventHandler(this, e);
}
}
private void OnLeave(Object source, EventArgs eventArgs)
{
HttpApplication app = (HttpApplication)source;
HttpContext context = app.Context;
if (context._Profile == null || (object)context._Profile == (object)ProfileBase.SingletonInstance)
return;
if (_AutoSaveEventHandler != null) {
ProfileAutoSaveEventArgs args = new ProfileAutoSaveEventArgs(context);
_AutoSaveEventHandler(this, args);
if (!args.ContinueWithProfileAutoSave)
return;
}
context.Profile.Save();
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
[SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.SerializationFormatter)]
internal static void ParseDataFromDB(string[] names, string values, byte[] buf, SettingsPropertyValueCollection properties)
{
if (names == null || values == null || buf == null || properties == null)
return;
try {
for (int iter = 0; iter < names.Length / 4; iter++) {
string name = names[iter * 4];
SettingsPropertyValue pp = properties[name];
if (pp == null) // property not found
continue;
int startPos = Int32.Parse(names[iter * 4 + 2], CultureInfo.InvariantCulture);
int length = Int32.Parse(names[iter * 4 + 3], CultureInfo.InvariantCulture);
if (length == -1 && !pp.Property.PropertyType.IsValueType) // Null Value
{
pp.PropertyValue = null;
pp.IsDirty = false;
pp.Deserialized = true;
}
if (names[iter * 4 + 1] == "S" && startPos >= 0 && length > 0 && values.Length >= startPos + length) {
pp.SerializedValue = values.Substring(startPos, length);
}
if (names[iter * 4 + 1] == "B" && startPos >= 0 && length > 0 && buf.Length >= startPos + length) {
byte[] buf2 = new byte[length];
Buffer.BlockCopy(buf, startPos, buf2, 0, length);
pp.SerializedValue = buf2;
}
}
} catch { // Eat exceptions
}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
[SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.SerializationFormatter)]
internal static void PrepareDataForSaving(ref string allNames, ref string allValues, ref byte[] buf, bool binarySupported, SettingsPropertyValueCollection properties, bool userIsAuthenticated)
{
StringBuilder names = new StringBuilder();
StringBuilder values = new StringBuilder();
MemoryStream ms = (binarySupported ? new System.IO.MemoryStream() : null);
try {
try {
bool anyItemsToSave = false;
foreach (SettingsPropertyValue pp in properties) {
if (pp.IsDirty) {
if (!userIsAuthenticated) {
bool allowAnonymous = (bool)pp.Property.Attributes["AllowAnonymous"];
if (!allowAnonymous)
continue;
}
anyItemsToSave = true;
break;
}
}
if (!anyItemsToSave)
return;
foreach (SettingsPropertyValue pp in properties) {
if (!userIsAuthenticated) {
bool allowAnonymous = (bool)pp.Property.Attributes["AllowAnonymous"];
if (!allowAnonymous)
continue;
}
if (!pp.IsDirty && pp.UsingDefaultValue) // Not fetched from DB and not written to
continue;
int len = 0, startPos = 0;
string propValue = null;
if (pp.Deserialized && pp.PropertyValue == null) // is value null?
{
len = -1;
} else {
object sVal = pp.SerializedValue;
if (sVal == null) {
len = -1;
} else {
if (!(sVal is string) && !binarySupported) {
sVal = Convert.ToBase64String((byte[])sVal);
}
if (sVal is string) {
propValue = (string)sVal;
len = propValue.Length;
startPos = values.Length;
} else {
byte[] b2 = (byte[])sVal;
startPos = (int)ms.Position;
ms.Write(b2, 0, b2.Length);
ms.Position = startPos + b2.Length;
len = b2.Length;
}
}
}
names.Append(pp.Name + ":" + ((propValue != null) ? "S" : "B") +
":" + startPos.ToString(CultureInfo.InvariantCulture) + ":" + len.ToString(CultureInfo.InvariantCulture) + ":");
if (propValue != null)
values.Append(propValue);
}
if (binarySupported) {
buf = ms.ToArray();
}
} finally {
if (ms != null)
ms.Close();
}
} catch {
throw;
}
allNames = names.ToString();
allValues = values.ToString();
}
}
public delegate void ProfileMigrateEventHandler(Object sender, ProfileMigrateEventArgs e);
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class ProfileMigrateEventArgs : EventArgs {
private HttpContext _Context;
private string _AnonymousId;
public HttpContext Context { get { return _Context;}}
public string AnonymousID { get { return _AnonymousId;}}
public ProfileMigrateEventArgs(HttpContext context, string anonymousId) {
_Context = context;
_AnonymousId = anonymousId;
}
}
public delegate void ProfileAutoSaveEventHandler(Object sender, ProfileAutoSaveEventArgs e);
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class ProfileAutoSaveEventArgs : EventArgs
{
private HttpContext _Context;
private bool _ContinueSave = true;
public HttpContext Context { get { return _Context; } }
public bool ContinueWithProfileAutoSave { get { return _ContinueSave; } set { _ContinueSave = value; }}
public ProfileAutoSaveEventArgs(HttpContext context) {
_Context = context;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* ProfileModule class
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Profile {
using System.Web;
using System.Text;
using System.Web.Compilation;
using System.Web.Configuration;
using System.Web.Caching;
using System.Collections;
using System.Web.Util;
using System.Security.Principal;
using System.Security.Permissions;
using System.Reflection;
using System.Web.Security;
using System.Globalization;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Configuration;
#if !FEATURE_PAL
using System.Web.DataAccess;
#endif // !FEATURE_PAL
///
/// [To be supplied.]
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ProfileModule : IHttpModule
{
private static object s_Lock = new object();
private ProfileEventHandler _eventHandler = null;
private ProfileMigrateEventHandler _MigrateEventHandler;
private ProfileAutoSaveEventHandler _AutoSaveEventHandler;
///
///
/// Initializes a new instance of the
/// class.
///
///
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
public ProfileModule()
{
}
///
/// This is a Global.asax event which must be
/// named FormsAuthorize_OnAuthorize event. It's used by advanced users to
/// customize cookie authentication.
///
public event ProfileEventHandler Personalize
{
add { _eventHandler += value; }
remove { _eventHandler -= value; }
}
public event ProfileMigrateEventHandler MigrateAnonymous
{
add { _MigrateEventHandler += value; }
remove { _MigrateEventHandler -= value; }
}
public event ProfileAutoSaveEventHandler ProfileAutoSaving {
add { _AutoSaveEventHandler += value; }
remove { _AutoSaveEventHandler -= value; }
}
///
/// [To be supplied.]
///
public void Dispose()
{
}
///
/// [To be supplied.]
///
public void Init(HttpApplication app)
{
if (ProfileManager.Enabled) {
app.AcquireRequestState += new EventHandler(this.OnEnter);
if (ProfileManager.AutomaticSaveEnabled) {
app.EndRequest += new EventHandler(this.OnLeave);
}
}
}
private void OnPersonalize(ProfileEventArgs e)
{
if (_eventHandler != null)
_eventHandler(this, e);
if (e.Profile != null)
{
e.Context._Profile = e.Profile;
return;
}
e.Context._ProfileDelayLoad = true;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
///
/// [To be supplied.]
///
private void OnEnter(Object source, EventArgs eventArgs)
{
HttpContext context = ((HttpApplication)source).Context;
OnPersonalize(new ProfileEventArgs(context));
if (context.Request.IsAuthenticated && !string.IsNullOrEmpty(context.Request.AnonymousID) && _MigrateEventHandler != null)
{
ProfileMigrateEventArgs e = new ProfileMigrateEventArgs(context, context.Request.AnonymousID);
_MigrateEventHandler(this, e);
}
}
private void OnLeave(Object source, EventArgs eventArgs)
{
HttpApplication app = (HttpApplication)source;
HttpContext context = app.Context;
if (context._Profile == null || (object)context._Profile == (object)ProfileBase.SingletonInstance)
return;
if (_AutoSaveEventHandler != null) {
ProfileAutoSaveEventArgs args = new ProfileAutoSaveEventArgs(context);
_AutoSaveEventHandler(this, args);
if (!args.ContinueWithProfileAutoSave)
return;
}
context.Profile.Save();
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
[SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.SerializationFormatter)]
internal static void ParseDataFromDB(string[] names, string values, byte[] buf, SettingsPropertyValueCollection properties)
{
if (names == null || values == null || buf == null || properties == null)
return;
try {
for (int iter = 0; iter < names.Length / 4; iter++) {
string name = names[iter * 4];
SettingsPropertyValue pp = properties[name];
if (pp == null) // property not found
continue;
int startPos = Int32.Parse(names[iter * 4 + 2], CultureInfo.InvariantCulture);
int length = Int32.Parse(names[iter * 4 + 3], CultureInfo.InvariantCulture);
if (length == -1 && !pp.Property.PropertyType.IsValueType) // Null Value
{
pp.PropertyValue = null;
pp.IsDirty = false;
pp.Deserialized = true;
}
if (names[iter * 4 + 1] == "S" && startPos >= 0 && length > 0 && values.Length >= startPos + length) {
pp.SerializedValue = values.Substring(startPos, length);
}
if (names[iter * 4 + 1] == "B" && startPos >= 0 && length > 0 && buf.Length >= startPos + length) {
byte[] buf2 = new byte[length];
Buffer.BlockCopy(buf, startPos, buf2, 0, length);
pp.SerializedValue = buf2;
}
}
} catch { // Eat exceptions
}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
[SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.SerializationFormatter)]
internal static void PrepareDataForSaving(ref string allNames, ref string allValues, ref byte[] buf, bool binarySupported, SettingsPropertyValueCollection properties, bool userIsAuthenticated)
{
StringBuilder names = new StringBuilder();
StringBuilder values = new StringBuilder();
MemoryStream ms = (binarySupported ? new System.IO.MemoryStream() : null);
try {
try {
bool anyItemsToSave = false;
foreach (SettingsPropertyValue pp in properties) {
if (pp.IsDirty) {
if (!userIsAuthenticated) {
bool allowAnonymous = (bool)pp.Property.Attributes["AllowAnonymous"];
if (!allowAnonymous)
continue;
}
anyItemsToSave = true;
break;
}
}
if (!anyItemsToSave)
return;
foreach (SettingsPropertyValue pp in properties) {
if (!userIsAuthenticated) {
bool allowAnonymous = (bool)pp.Property.Attributes["AllowAnonymous"];
if (!allowAnonymous)
continue;
}
if (!pp.IsDirty && pp.UsingDefaultValue) // Not fetched from DB and not written to
continue;
int len = 0, startPos = 0;
string propValue = null;
if (pp.Deserialized && pp.PropertyValue == null) // is value null?
{
len = -1;
} else {
object sVal = pp.SerializedValue;
if (sVal == null) {
len = -1;
} else {
if (!(sVal is string) && !binarySupported) {
sVal = Convert.ToBase64String((byte[])sVal);
}
if (sVal is string) {
propValue = (string)sVal;
len = propValue.Length;
startPos = values.Length;
} else {
byte[] b2 = (byte[])sVal;
startPos = (int)ms.Position;
ms.Write(b2, 0, b2.Length);
ms.Position = startPos + b2.Length;
len = b2.Length;
}
}
}
names.Append(pp.Name + ":" + ((propValue != null) ? "S" : "B") +
":" + startPos.ToString(CultureInfo.InvariantCulture) + ":" + len.ToString(CultureInfo.InvariantCulture) + ":");
if (propValue != null)
values.Append(propValue);
}
if (binarySupported) {
buf = ms.ToArray();
}
} finally {
if (ms != null)
ms.Close();
}
} catch {
throw;
}
allNames = names.ToString();
allValues = values.ToString();
}
}
public delegate void ProfileMigrateEventHandler(Object sender, ProfileMigrateEventArgs e);
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class ProfileMigrateEventArgs : EventArgs {
private HttpContext _Context;
private string _AnonymousId;
public HttpContext Context { get { return _Context;}}
public string AnonymousID { get { return _AnonymousId;}}
public ProfileMigrateEventArgs(HttpContext context, string anonymousId) {
_Context = context;
_AnonymousId = anonymousId;
}
}
public delegate void ProfileAutoSaveEventHandler(Object sender, ProfileAutoSaveEventArgs e);
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class ProfileAutoSaveEventArgs : EventArgs
{
private HttpContext _Context;
private bool _ContinueSave = true;
public HttpContext Context { get { return _Context; } }
public bool ContinueWithProfileAutoSave { get { return _ContinueSave; } set { _ContinueSave = value; }}
public ProfileAutoSaveEventArgs(HttpContext context) {
_Context = context;
}
}
}
// 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
- BamlRecordWriter.cs
- SqlProcedureAttribute.cs
- MarkupCompilePass1.cs
- CaretElement.cs
- ObjectListItemCollection.cs
- RegexRunnerFactory.cs
- SelectionPattern.cs
- PageContentAsyncResult.cs
- Pointer.cs
- AutomationEvent.cs
- DoWorkEventArgs.cs
- OrderedDictionaryStateHelper.cs
- DeferredTextReference.cs
- _SecureChannel.cs
- RNGCryptoServiceProvider.cs
- BoundColumn.cs
- DBAsyncResult.cs
- CustomLineCap.cs
- DashStyle.cs
- ExpandSegmentCollection.cs
- WorkItem.cs
- WebAdminConfigurationHelper.cs
- UiaCoreProviderApi.cs
- DataKeyPropertyAttribute.cs
- HijriCalendar.cs
- Pair.cs
- DataControlFieldHeaderCell.cs
- TransactionScope.cs
- FontWeightConverter.cs
- TextAdaptor.cs
- XmlLanguage.cs
- SiteMapPath.cs
- XmlArrayItemAttributes.cs
- PropertyInfoSet.cs
- OleDbPropertySetGuid.cs
- WindowsListViewGroup.cs
- MasterPageBuildProvider.cs
- VirtualDirectoryMappingCollection.cs
- Int32CAMarshaler.cs
- GeneralTransform2DTo3D.cs
- UnauthorizedAccessException.cs
- RouteTable.cs
- TextTreeRootTextBlock.cs
- XmlLanguageConverter.cs
- ButtonBase.cs
- ObjectParameterCollection.cs
- TableLayoutPanelCellPosition.cs
- DataFormats.cs
- SmtpCommands.cs
- PreloadedPackages.cs
- XmlSchemaGroup.cs
- Message.cs
- configsystem.cs
- MenuItemStyleCollectionEditor.cs
- UInt64Converter.cs
- DbConnectionPoolGroupProviderInfo.cs
- CodeDomDesignerLoader.cs
- XmlNamespaceMapping.cs
- RolePrincipal.cs
- MimeReflector.cs
- ConfigXmlWhitespace.cs
- XmlNullResolver.cs
- MessageHeaderAttribute.cs
- RemotingConfigParser.cs
- DbSourceCommand.cs
- SrgsGrammarCompiler.cs
- RegexRunner.cs
- XmlSchemaNotation.cs
- SecuritySessionFilter.cs
- PublishLicense.cs
- FormatPage.cs
- WebZone.cs
- storagemappingitemcollection.viewdictionary.cs
- ObjectDataSourceView.cs
- ToolboxCategory.cs
- NativeMethods.cs
- ResponseStream.cs
- SessionKeyExpiredException.cs
- ListViewUpdateEventArgs.cs
- Version.cs
- SQLMoneyStorage.cs
- Int32CAMarshaler.cs
- DBDataPermissionAttribute.cs
- DocumentGridContextMenu.cs
- UTF32Encoding.cs
- _BaseOverlappedAsyncResult.cs
- DataGridCommandEventArgs.cs
- TextComposition.cs
- RuleSettings.cs
- ApplicationBuildProvider.cs
- DataBinding.cs
- Border.cs
- PersonalizationProviderCollection.cs
- FailedToStartupUIException.cs
- ZoneLinkButton.cs
- ClientConfigPaths.cs
- FontDialog.cs
- ThicknessKeyFrameCollection.cs
- BindingCompleteEventArgs.cs
- ToolStripComboBox.cs