////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////

        public override void SetPropertyValues(SettingsContext sc, SettingsPropertyValueCollection properties)
        {
            string username            = (string)sc["UserName"];
            bool   userIsAuthenticated = (bool)sc["IsAuthenticated"];

            if (username == null || username.Length < 1 || properties.Count < 1)
            {
                return;
            }

            string names  = String.Empty;
            string values = String.Empty;

            byte [] buf = null;

            ProfileModule.PrepareDataForSaving(ref names, ref values, ref buf, true, properties, userIsAuthenticated);
            if (names.Length == 0)
            {
                return;
            }

            try {
                SqlConnectionHolder holder = null;
                try
                {
                    holder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true);
                    CheckSchemaVersion(holder.Connection);

                    SqlCommand cmd = new SqlCommand("dbo.aspnet_Profile_SetProperties", holder.Connection);

                    cmd.CommandTimeout = CommandTimeout;
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.Parameters.Add(CreateInputParam("@ApplicationName", SqlDbType.NVarChar, ApplicationName));
                    cmd.Parameters.Add(CreateInputParam("@UserName", SqlDbType.NVarChar, username));
                    cmd.Parameters.Add(CreateInputParam("@PropertyNames", SqlDbType.NText, names));
                    cmd.Parameters.Add(CreateInputParam("@PropertyValuesString", SqlDbType.NText, values));
                    cmd.Parameters.Add(CreateInputParam("@PropertyValuesBinary", SqlDbType.Image, buf));
                    cmd.Parameters.Add(CreateInputParam("@IsUserAnonymous", SqlDbType.Bit, !userIsAuthenticated));
                    cmd.Parameters.Add(CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
                    cmd.ExecuteNonQuery();
                }
                finally {
                    if (holder != null)
                    {
                        holder.Close();
                        holder = null;
                    }
                }
            } catch {
                throw;
            }
        }
Beispiel #2
0
        public override void SetPropertyValues(SettingsContext sc, SettingsPropertyValueCollection properties)
        {
            string objValue            = (string)sc["UserName"];
            bool   userIsAuthenticated = (bool)sc["IsAuthenticated"];

            if (((objValue != null) && (objValue.Length >= 1)) && (properties.Count >= 1))
            {
                string allNames  = string.Empty;
                string allValues = string.Empty;
                byte[] buf       = null;
                ProfileModule.PrepareDataForSaving(ref allNames, ref allValues, ref buf, true, properties, userIsAuthenticated);
                if (allNames.Length != 0)
                {
                    try
                    {
                        SqlConnectionHolder connection = null;
                        try
                        {
                            connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                            this.CheckSchemaVersion(connection.Connection);
                            SqlCommand command = new SqlCommand("dbo.aspnet_Profile_SetProperties", connection.Connection)
                            {
                                CommandTimeout = this.CommandTimeout,
                                CommandType    = CommandType.StoredProcedure
                            };
                            command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName));
                            command.Parameters.Add(this.CreateInputParam("@UserName", SqlDbType.NVarChar, objValue));
                            command.Parameters.Add(this.CreateInputParam("@PropertyNames", SqlDbType.NText, allNames));
                            command.Parameters.Add(this.CreateInputParam("@PropertyValuesString", SqlDbType.NText, allValues));
                            command.Parameters.Add(this.CreateInputParam("@PropertyValuesBinary", SqlDbType.Image, buf));
                            command.Parameters.Add(this.CreateInputParam("@IsUserAnonymous", SqlDbType.Bit, !userIsAuthenticated));
                            command.Parameters.Add(this.CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
                            command.ExecuteNonQuery();
                        }
                        finally
                        {
                            if (connection != null)
                            {
                                connection.Close();
                                connection = null;
                            }
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
        {
            HttpContext context = HttpContext.Current;

            if (context != null && HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_BEGIN, HttpContext.Current.WorkerRequest);
            }

            string[] names  = null;
            string   values = null;

            byte[] buf   = null;
            string sName = null;

            if (context != null)
            {
                sName = (context.Request.IsAuthenticated ? context.User.Identity.Name : context.Request.AnonymousID);
            }

            try {
                SqlConnectionHolder holder = null;
                SqlDataReader       reader = null;
                try
                {
                    holder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true);
                    CheckSchemaVersion(holder.Connection);
                    SqlCommand cmd = new SqlCommand("dbo.aspnet_Profile_GetProperties", holder.Connection);

                    cmd.CommandTimeout = CommandTimeout;
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.Parameters.Add(CreateInputParam("@ApplicationName", SqlDbType.NVarChar, ApplicationName));
                    cmd.Parameters.Add(CreateInputParam("@UserName", SqlDbType.NVarChar, userName));
                    cmd.Parameters.Add(CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
                    reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
                    if (reader.Read())
                    {
                        names  = reader.GetString(0).Split(':');
                        values = reader.GetString(1);

                        int size = (int)reader.GetBytes(2, 0, null, 0, 0);

                        buf = new byte[size];
                        reader.GetBytes(2, 0, buf, 0, size);
                    }
                } finally {
                    if (holder != null)
                    {
                        holder.Close();
                        holder = null;
                    }

                    if (reader != null)
                    {
                        reader.Close();
                    }
                }

                ProfileModule.ParseDataFromDB(names, values, buf, svc);

                if (context != null && HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc))
                {
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_END, HttpContext.Current.WorkerRequest, userName);
                }
            } catch {
                throw;
            }
        }
Beispiel #4
0
        private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
        {
            if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_BEGIN, HttpContext.Current.WorkerRequest);
            }
            HttpContext current = HttpContext.Current;

            string[] names  = null;
            string   values = null;

            byte[] buffer = null;
            if (current != null)
            {
                if (!current.Request.IsAuthenticated)
                {
                    string anonymousID = current.Request.AnonymousID;
                }
                else
                {
                    string name = current.User.Identity.Name;
                }
            }
            try
            {
                SqlConnectionHolder connection = null;
                SqlDataReader       reader     = null;
                try
                {
                    connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    this.CheckSchemaVersion(connection.Connection);
                    SqlCommand command = new SqlCommand("dbo.aspnet_Profile_GetProperties", connection.Connection)
                    {
                        CommandTimeout = this.CommandTimeout,
                        CommandType    = CommandType.StoredProcedure
                    };
                    command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName));
                    command.Parameters.Add(this.CreateInputParam("@UserName", SqlDbType.NVarChar, userName));
                    command.Parameters.Add(this.CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
                    reader = command.ExecuteReader(CommandBehavior.SingleRow);
                    if (reader.Read())
                    {
                        names  = reader.GetString(0).Split(new char[] { ':' });
                        values = reader.GetString(1);
                        int length = (int)reader.GetBytes(2, 0L, null, 0, 0);
                        buffer = new byte[length];
                        reader.GetBytes(2, 0L, buffer, 0, length);
                    }
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Close();
                        connection = null;
                    }
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                ProfileModule.ParseDataFromDB(names, values, buffer, svc);
                if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
                {
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_END, HttpContext.Current.WorkerRequest, userName);
                }
            }
            catch
            {
                throw;
            }
        }