Data Entries in aspnet_Users and aspnet_Profile

Vote:
 

Hi,

My Site is an EPiServer CMS(7.14) and EPiServer Commerce Site(8.1.0)

We just Noticed that these tables are growing massivels with guid based entries. Those are not real users.

  • aspnet_Users    3433382
  • aspnet_Profile  3432545

I did a test in my dev enviornments

select count(*) from  aspnet_Users

count was 3342

I accessed the site in New browser
count was increased to count was 3343.

Does it mean EPiServer is adding an entry automatically for anonymous users?

Is it a bug? Can I stop this. On my live site figure is massive. 

How can i clear those annoymous entries?

Regards
Khurram

#114822
Dec 23, 2014 13:01
Vote:
 

If am not wrong this is the tables that handles IIS-users, if you open the site in IIS, can you see a lot of users there?

What do you use for membership provider?

#114832
Dec 23, 2014 17:29
Vote:
 

Thanks Henrik for response and aologize i couldn't response in time due to holidays season. What do you meant by "Open the site in IIS".

Although iwas using a custom mebership provider but when i observered the table sizes on Live site In my development i testeed with with built-in provider and results were same.

<membership defaultProvider="CMSMembershipProvider" userIsOnlineTimeWindow="10" hashAlgorithmType="HMACSHA512">

<providers>
<clear />
<add name="MultiplexingMembershipProvider" type="EPiServer.Security.MultiplexingMembershipProvider, EPiServer.Framework" provider1="SqlServerMembershipProvider" provider2="WindowsMembershipProvider" />
....
<!-- ECF Start -->
<add connectionStringName="EcfSqlConnection" applicationName="ABCDEFD" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" passwordStrengthRegularExpression="" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" name="CMSMembershipProvider" type="Mediachase.Commerce.Customers.Profile.Providers.CustomerSqlMembershipProvider, Mediachase.Commerce" />
<!-- ECF End -->
</providers>
</membership>

#114989
Jan 07, 2015 12:14
Vote:
 

Sorry, open the site in IIS Manager I mean :)

Ok, I have not seen it in any sites,

#114990
Jan 07, 2015 12:37
Vote:
 

I can replicate in commerec sample site also.
a function UpdateProfile in
EPiServer.Commerce.Sample.Helpers.MarketStorage

is creatinga profile for each anonymous user. can be replicated by clearing the cookies.

Why I have so many entries, In theory Search Engine / Other Spider tools (Screaming Frog)  to crawl through the whole website were not using cookie and in result were creating entries. we have to update the logic to get the rid of this profile entry.

Regards
/K

#115133
Jan 09, 2015 15:34
Vote:
 

Was able to reproduce this via an RTM Commerce 7.5 site and sample site via the following steps:

1. Open Commerce 7.5 sample site. See that aspnet_Users and aspnet_Profile tables in Commerce Manager database are empty or have non-anonymous (default) data.

2. Change Market from top menu. For example, switch from Default Market to another country

3. Clear cookies and cache from browser. Close browser.

4. Open site again and check the aspnet_Users and aspnet__Profile tables to see population by anonymous data.

#115142
Jan 09, 2015 21:17
Vote:
 

Hi,

A update related to the issue: MarketStorage is a sample implementation of ICurrentMarket, where it uses asp.net Profile to store market id. You're free to choose the way you want to store your own. The way we do it now is if the user is authenticated, then use Profile like before, otherwise fallback to use cookies.

The related bug is fixed but will not be available anytime soon - as we don't deliver Sample packages. You need to update your own code, here's what it looks like, more or less:

using System;
using System.Web;
using System.Web.Profile;
using Mediachase.Commerce;
using Mediachase.Commerce.Core;
using Mediachase.Commerce.Markets;
using Mediachase.Commerce.Website;
using EPiServer.Security;
using System.Web.SessionState;

namespace EPiServer.Commerce.Sample.Helpers
{
    /// <summary>
    /// Implementation of current market selection that stores information in user profile.
    /// </summary>
    public class MarketStorage : ICurrentMarket
    {
        private const string _marketIdKey = "MarketId";
        private readonly IMarketService _marketService;

        /// <summary>
        /// Initializes a new instance of the <see cref="MarketStorage"/> class.
        /// </summary>
        public MarketStorage()
            : this(ServiceLocation.ServiceLocator.Current.GetInstance<IMarketService>())
        { }

        /// <summary>
        /// Initializes a new instance of the <see cref="MarketStorage"/> class.
        /// </summary>
        /// <param name="marketService">The market service.</param>
        public MarketStorage(IMarketService marketService)
        {
            _marketService = marketService;
        }

        /// <summary>
        /// Gets the <see cref="IMarket"/> selected in the current user profile, if the value is
        /// set and the indicated market is valid; ; otherwise, gets the default <see cref="IMarket"/>.
        /// </summary>
        /// <returns>The current <see cref="IMarket"/>.</returns>
        public IMarket GetCurrentMarket()
        {
            var profileMarketId = GetStoredMarketId();
            
            var marketId = string.IsNullOrEmpty(profileMarketId) ? MarketId.Default : new MarketId(profileMarketId);
            var market = _marketService.GetMarket(marketId);

            if (market == null && marketId != MarketId.Default)
            {
                market = _marketService.GetMarket(MarketId.Default);
            }

            UpdateProfile(market);

            return market;
        }

        /// <summary>
        /// Sets the current market, if <paramref name="marketId"/> represents a valid market;
        /// otherwise, performs no action.
        /// </summary>
        /// <param name="marketId">The market id.</param>
        /// <remarks>This will also set the current currency for the ECF context.</remarks>
        public void SetCurrentMarket(MarketId marketId)
        {
            var market = _marketService.GetMarket(marketId);
            if (market != null)
            {
                UpdateProfile(market);
                SiteContext.Current.Currency = market.DefaultCurrency;
                Globalization.ContentLanguage.PreferredCulture = market.DefaultLanguage;
            }
        }

        /// <summary>
        /// Updates the profile.
        /// </summary>
        /// <param name="market">The market.</param>
        /// <remarks>Store selected market id in profile if user is logged in, otherwise store it in cookie.</remarks>
        private void UpdateProfile(IMarket market)
        {
            var profile = GetProfileStorage();
            if (profile != null)
            {
                UpdateProfile(profile, market);
            }
            else if (HttpContext.Current != null)
            {
                UpdateProfile(HttpContext.Current.Response, market);
            }
        }

        private void UpdateProfile(ProfileBase profileStorage, IMarket market)
        {
            var originalMarketId = profileStorage[_marketIdKey] as string;
            var currentMarketId = market == null || market.MarketId == MarketId.Default ? string.Empty : market.MarketId.Value;
            if (!string.Equals(originalMarketId, currentMarketId, StringComparison.Ordinal))
            {
                profileStorage[_marketIdKey] = currentMarketId;
                profileStorage.Save();
            }
        }

        private void UpdateProfile(HttpResponse response, IMarket market)
        {
            var cookie = response.Cookies[_marketIdKey];
            var originalMarketId = cookie == null ? string.Empty : cookie.Value;
            var currentMarketId = market == null || market.MarketId == MarketId.Default ? string.Empty : market.MarketId.Value;
            if (!string.Equals(originalMarketId, currentMarketId, StringComparison.Ordinal))
            {
                cookie = new HttpCookie(_marketIdKey, currentMarketId);
                response.SetCookie(cookie);
            }
        }

        private ProfileBase GetProfileStorage()
        {
            var httpContext = HttpContext.Current;
            if (httpContext != null && httpContext.User.Identity.IsAuthenticated)
            {
                return httpContext.Profile;
            }
            return null;
        }

        /// <summary>
        /// Gets the stored market identifier.
        /// </summary>
        /// <returns></returns>
        /// <remarks>If user is logged in, try to get market id from profile,
        /// otherwise, get it from cookie.</remarks>
        private string GetStoredMarketId()
        {
            if (HttpContext.Current == null)
            {
                return string.Empty;
            }
            var profileStorage = GetProfileStorage();
            if (profileStorage != null)
            {
                return profileStorage[_marketIdKey] as string;
            }
            var cookie =  HttpContext.Current.Request.Cookies[_marketIdKey];
            if (cookie != null)
            {
                return cookie.Value;
            }
            return string.Empty; 
        }
    }
}

Regards.

/Q

#115428
Jan 15, 2015 5:37
Vote:
 

Many Thanks Quan, i will turn this solution as BLog for developer's reference

Regards
/K

#115435
Jan 15, 2015 9:13
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.