locked
Profile provider that uses session? RRS feed

  • Question

  • User1278809144 posted

    Hi all,

    I'm working on a web app and our current portfolio is a set of web apps (up to .Net 3.5) with Oracle databases, however the data provider we are currently using is ODP 10.1.  I'd like to use the new Profile model to save user customization, however this would require that we have an Oracle Profile Provider.  Of the options out there, the best options I have come up with end up as either write my own or wait until we can upgrade to Oracle ODP 11.1 (thus able to use Oracles new ODAC including Oracle Providers for ASP), however we have time for neither of those options right now.

    As a compromise, I'd like to continue writing my app, using the Profile structure (Profile.store...) and build everything up that I'd need to store the data in a profile model, but configure a provider that would simply store the data in Session.  As a result, for the time being, the app would load up and use default values, allow the user to customize and remember those during the current session, but then loose them when they leave the site, but more importantly, when we get to a point where we have access to an Oracle Profile Provider, it should be a simple configuration change to get it working.

    Does anyone know of something that sounds like what I'm describing?

    Thanks,
    ~Jeff

    Thursday, February 26, 2009 1:24 PM

Answers

  • User-2115483147 posted

    As we know if we want to use the thread profile provider, we just need to implement the provider.

    So, could you tell me how do you implement the provider?

    Here is one sample, the sample will show you how to implement the provider,

    http://msdn.microsoft.com/en-us/library/ta63b872.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 2, 2009 9:47 PM

All replies

  • User-2115483147 posted

    Hi Jeff,

    Sorry, I do not understanding the question well as you mentioned.  But I have a question for you, have you implement session state provider and profile provider?

    If not, please check this link, and download the providers,

    http://www.oracle.com/technology/tech/dotnet/aspnet/index.html

     

    Monday, March 2, 2009 2:11 AM
  • User1278809144 posted

    Sorry I wasn't clear.

    The Oracle providers for ASP look to be exactly what I need however all of our current applications are on ODP.NET 10.1, so in order to use them, we would have to upgrade to using 11.1.  In the environment we are in, the effort including paperwork, actual upgrade, and testing would be far mor than we're able to handle right now, so this isn't exactly feasable, however it's not unlikely we won't do the upgrade in the near future.

    Knowing we might be able to do that upgrade soon, I'd like to plan for it and code my current app to be able to take advantage of the Profile model, saving variables on a per user basis for personalization of the web app.

    For the time being, I need to at least be able to maintain the users settings for the duration of a visit, so I'd like to find a Profile Provider that simply saves the variables off to Session.  This would allow my users to have all of their personalization data saved for the duration of a visit to the site, and when we are ready to make that 11.1 upgrade, I can simply change the web.config file to use the Oracle Profile Provider and I that should make my app instantly save across visits too.

    I'm working on writing one now, however I'm having some issues as the final firing of the save seems to be happening after the "Session" has gone away for a given postback.  I'm working out the details, but was wondering if anyone knows of something similar.

    Thanks,

    ~Jeff

     

     

    Monday, March 2, 2009 8:26 AM
  • User-2115483147 posted

    As we know if we want to use the thread profile provider, we just need to implement the provider.

    So, could you tell me how do you implement the provider?

    Here is one sample, the sample will show you how to implement the provider,

    http://msdn.microsoft.com/en-us/library/ta63b872.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 2, 2009 9:47 PM
  • User-25987487 posted

     There is a implementation in the AjaxControlToolkit. See AjaxControlToolkit.zip - \SampleWebSite\App_Code\SessionProfileProvider.cs

     

    // (c) Copyright Microsoft Corporation.
    // This source is subject to the Microsoft Permissive License.
    // See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
    // All other rights reserved.
    
    
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Web.Profile;
    
    /// <summary>
    /// A stub implementation of a profile provider that lets us save values into
    /// the session instead of creating a DB
    /// </summary>
    public class SessionProfileProvider : ProfileProvider
    {
        private static Dictionary<string, Dictionary<string, object>> _profileValues = new Dictionary<string, Dictionary<string, object>>();
    
        public SessionProfileProvider()
        {
        }
    
        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override int DeleteProfiles(string[] usernames)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    
        public override string ApplicationName
        {
            get { return "ToolkitSampleWebsite"; }
            set { }
        }
    
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            string username = (string)context["UserName"];
            bool isAuthenticated = (bool)context["IsAuthenticated"];
    
            Dictionary<string, object> values = _profileValues.ContainsKey(username) ? _profileValues[username] : null;
    
            SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection();
            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue spv = new SettingsPropertyValue(prop);
                if (values != null && values.ContainsKey(prop.Name))
                {
                    spv.PropertyValue = values[prop.Name];
                }
                else
                {
                    spv.PropertyValue = prop.DefaultValue;
                }
                spvc.Add(spv);
            }
            return spvc;
        }
    
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            string username = (string)context["UserName"];
            bool isAuthenticated = (bool)context["IsAuthenticated"];
    
            Dictionary<string, object> values = _profileValues.ContainsKey(username) ? _profileValues[username] : null;
    
            if (values == null)
            {
                values = new Dictionary<string, object>();
                _profileValues[username] = values;
            }
    
            foreach (SettingsPropertyValue propValue in collection)
            {
                values[propValue.Property.Name] = propValue.PropertyValue;
            }
        }
    }
      
    Wednesday, March 25, 2009 10:00 PM