Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to find source for SqlProfileProvider.cs file
Message
De
10/04/2008 01:05:31
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01309118
Message ID:
01309585
Vues:
21
This message has been marked as a message which has helped to the initial question of the thread.
In this line:

SqlCommand cmd = new SqlCommand("UPDATE aspnet_Users SET LastActivityDate = @LastUpdatedDate WHERE UserId = '" + userId + "'", conn);

What is the value of userId when it executes?

As to why UTCNow see this:

http://aspnet.4guysfromrolla.com/articles/081507-1.aspx

John



>Interestingly, googling on "UpdateLastActivityDate" brings only few results with most of them in Chinese...
>
>I'm guessing that something is wrong in our implementation, but I really could not figure this problem out. What code exactly is called by the Login page (it doesn't seem to have cs file at all with code - so it must be internal code by MS). But why when all users get updated with the same date? And why the code uses UTCNow date instead of just Date.Now ?
>
>Anyone here knows the answer?
>
>Thanks a lot in advance.
>
>>Hi everybody,
>>
>>I see we're using this class copyright file="SqlProfileProvider.cs" company="Microsoft" with several modifications from the original programmer who doesn't work here anymore.
>>
>>This file has the following code and I'm trying to understand it and figure out why does it update last activity date for all users for this site and not only the particular user (me) who just logged. Perhaps I'm just not seeing the problem:
>>
>>
>>private void GetProfileDataFromTable(SettingsPropertyCollection properties, SettingsPropertyValueCollection svc, string username, SqlConnection conn) {
>>            List<ProfileColumnData> columnData = new List<ProfileColumnData>(properties.Count);
>>            StringBuilder commandText = new StringBuilder("SELECT u.UserID");
>>            SqlCommand cmd = new SqlCommand(String.Empty, conn);
>>
>>            int columnCount = 0;
>>            foreach (SettingsProperty prop in properties) {
>>                SettingsPropertyValue value = new SettingsPropertyValue(prop);
>>                svc.Add(value);
>>
>>                string persistenceData = prop.Attributes["CustomProviderData"] as string;
>>                // If we can't find the table/column info we will ignore this data
>>                if (String.IsNullOrEmpty(persistenceData)) {
>>                    // REVIEW: Perhaps we should throw instead?
>>                    continue;
>>                }
>>                string[] chunk = persistenceData.Split(new char[] { ';' });
>>                if (chunk.Length != 2) {
>>                    // REVIEW: Perhaps we should throw instead?
>>                    continue;
>>                }
>>                string columnName = chunk[0];
>>                // REVIEW: Should we ignore case?
>>                SqlDbType datatype = (SqlDbType)Enum.Parse(typeof(SqlDbType), chunk[1], true);
>>
>>                columnData.Add(new ProfileColumnData(columnName, value, null /* not needed for get */, datatype));
>>                commandText.Append(", ");
>>                commandText.Append("t."+columnName);
>>                ++columnCount;
>>            }
>>            //Added Nolock for speed Ephraim
>>            commandText.Append(" FROM "+_table+" AS t WITH (NOLOCK), vw_aspnet_Users u WHERE u.ApplicationId = '").Append(AppId);
>>            commandText.Append("' AND u.UserName = LOWER(@Username) AND t.UserID = u.UserID");
>>            cmd.CommandText = commandText.ToString();
>>            cmd.CommandType = CommandType.Text;
>>            cmd.Parameters.AddWithValue("@Username", username);
>>            SqlDataReader reader = null;
>>
>>            try {
>>                reader = cmd.ExecuteReader();
>>                //If no row exists in the database, then the default Profile values
>>                //from configuration are used.
>>                if (reader.Read()) {
>>                    Guid userId = reader.GetGuid(0);
>>                    for (int i = 0; i < columnData.Count; ++i) {
>>                        object val = reader.GetValue(i+1);
>>                        ProfileColumnData colData = columnData[i];
>>                        SettingsPropertyValue propValue = colData.PropertyValue;
>>
>>                        //Only initialize a SettingsPropertyValue for non-null values
>>                        if (!(val is DBNull || val == null))
>>                        {
>>                            propValue.PropertyValue = val;
>>                            propValue.IsDirty = false;
>>                            propValue.Deserialized = true;
>>                        }
>>                    }
>>
>>                    // need to close reader before we try to update the user
>>                    if (reader != null) {
>>                        reader.Close();
>>                        reader = null;
>>                    }
>>
>>                    UpdateLastActivityDate(conn, userId);
>>
>>                }
>>            }
>>            finally {
>>                if (reader != null) {
>>                    reader.Close();
>>                }
>>            }
>>        }
>>
>>        private static void UpdateLastActivityDate(SqlConnection conn, Guid userId) {
>>            SqlCommand cmd = new SqlCommand("UPDATE aspnet_Users SET LastActivityDate = @LastUpdatedDate WHERE UserId = '" + userId + "'", conn);
>>            cmd.CommandType = CommandType.Text;
>>            cmd.Parameters.AddWithValue("@LastUpdatedDate", DateTime.UtcNow);
>>            try {
>>                cmd.ExecuteNonQuery();
>>            }
>>            finally {
>>                cmd.Dispose();
>>            }
>>        }
>>
>>
>>Thanks a lot in advance.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform