none
Profile Common in Web Application RRS feed

  • Question

  • Hi,

       Recently I have converted WebSite project to Web Application Project. Evrything is good, But the problem is ProfileCommon. In Website project type ProfileCommon by default will give the all options But in WebApplication it is not.

      So I have created ProfileCommon class by own and it's implement / Derives the PrifileBase Class. and my class look like below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Profile;
    using System.Web.Security;


    public class ProfileCommon : ProfileBase
    {
        public virtual bool AllTypes
        {
            get
            {
                return ((bool)(this.GetPropertyValueAllTypes
            }
            set
            {
                this.SetPropertyValueAllTypesvalue);
            }
        }
    }


       And I have made the changes in Web.Config like I have removed all property keys as well. But When I try to run the Application I am getting run time issue like :

            Unable to cast object of type 'System.Web.Profile.DefaultProfile' to type 'ProfileCommon'

      And the Issue is from one of my properties:

      public static ProfileCommon GetProfile(string username) 

    {

          return ((ProfileName)(ProfileBase.Create(username)));

    }

    Please let me know If Any suggestions on the problem.


    Tuesday, April 1, 2014 8:23 PM

Answers

  • Hello,

    For converting a web site project to a web application, you can check this walkthrough:

    Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio

    Search for Converting Profile Object Code section, we can see that it use codes as below to create our own ProfileCommon class that contains strongly typed properties for the items configured in the profile system:

    public class ProfileCommon
    
        {
    
            public Teachers Teachers
    
            {
    
                get
    
                    {
    
                    return (Teachers) HttpContext.Current.Profile.GetPropertyValue("Teachers");
    
                    }
    
                set
    
                {
    
            HttpContext.Current.Profile.SetPropertyValue("Teachers",value);
    
                }
    
            }
    
    }
    

    By the way, this forum is used to discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    For issues regarding ASP.NET, there is a specific forum:

    http://forums.asp.net/

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 2, 2014 8:30 AM
    Moderator