Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:55:07+00:00 2026-06-08T17:55:07+00:00

I recently asked this question How to persist anon user selection (ex: theme selection)

  • 0

I recently asked this question How to persist anon user selection (ex: theme selection). and started to learn about ASP.NET profiles and their properties in the web config. I tried the answer from the link but i was unable to access profile.newproperty

How to assign Profile values?
This question specifies that web-applications don’t support profile out of the box and a custom model based on ProfileBase must be created. The question was answered in 2009 and I wanted to know if this is still the same case.

In a ASP.NET 4.0 web application can I access profile.newproperty with a property i defined in the section in the web.config without needing to code C# except when accessing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:55:09+00:00Added an answer on June 8, 2026 at 5:55 pm

    I just saw your question, yes you are right, the answer I posted was related to web sites and therefore, it doesn’t work with Web Applications or MVC

    Here I will show you code to work with profiles in MVC using anonymous and authenticated user profiles

    Output

    Anonymous user – No profile set yet

    enter image description here

    Anonymous user – profile set

    enter image description here

    Authenticated user – profile migrated

    enter image description here

    Web.config

    <anonymousIdentification enabled="true"/>
    <profile inherits="ProfileInWebApplicationMVC1.UserProfile">
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
    

    UserProfile class

    public class UserProfile : ProfileBase
    {
        public static UserProfile GetProfile()
        {
            return HttpContext.Current.Profile as UserProfile;
        }
    
        [SettingsAllowAnonymous(true)]
        public DateTime? LastVisit
        {
            get { return base["LastVisit"] as DateTime?; }
            set { base["LastVisit"] = value; }
        }
    
        public static UserProfile GetProfile(string userID)
        {
            return ProfileBase.Create(userID) as UserProfile;
        }
    }
    

    Home controller

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
    
            var p = UserProfile.GetProfile();
    
            return View(p.LastVisit);
        }
    
        [HttpPost]
        public ActionResult SaveProfile()
        {
            var p = UserProfile.GetProfile();
    
            p.LastVisit = DateTime.Now;
            p.Save();
    
            return RedirectToAction("Index");
        }
    

    Index view

    @if (!this.Model.HasValue)
    {
        @: No profile detected
    }
    else
    {
        @this.Model.Value.ToString()
    }
    
    @using (Html.BeginForm("SaveProfile", "Home"))
    {
        <input type="submit" name="name" value="Save profile" />
    }
    

    And finally, when you are an anonymous user you can have your own profile however, once you register to the site, you need to migrate your current profile to be used with your new account. This is because ASP.Net membership, creates a new profile when a user logs-in

    Global.asax, code to migrate profiles

        public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            var anonymousProfile = UserProfile.GetProfile(args.AnonymousID);
            var f = UserProfile.GetProfile(); // current logged in user profile
    
            if (anonymousProfile.LastVisit.HasValue)
            {
                f.LastVisit = anonymousProfile.LastVisit;
                f.Save();
            }
    
            ProfileManager.DeleteProfile(args.AnonymousID);
            AnonymousIdentificationModule.ClearAnonymousIdentifier();
            Membership.DeleteUser(args.AnonymousID, true);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I originally asked this question about an hour ago but only recently realized
I recently asked this question about how to simulate type classes in D and
I asked this question over on the asp.net forums, and nobody seems to know
This question is related to this other question I recently asked... cf.net exception and
(This question is asked on Maven User mailing list too) I have recently faced
This is related to another question I recently asked about storing a non-bare repository
Recently I asked this question: Find Common Values in several arrays, or lists VB.NET
I recently asked this question: MS SQL share identity seed amongst tables (Many people
I was recently asked this question in an interview. Lets suppose I have 2000
I was recently asked this question : What is the difference between String and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.