How to persist anon user selection (ex: theme selection)

后端 未结 1 1977
终归单人心
终归单人心 2020-12-20 07:43

Sorry for the ambiguous question but here I go.

On each page a have a partial view displaying different theme options. These themes are just different css classes fo

1条回答
  •  礼貌的吻别
    2020-12-20 08:25

    You could use a concept known as Profile

    With profiles you can declare the properties you would like to expose to your users and this works for anonymous users

    Basically the profile properties are stored in cookies, therefore you can configure when they should expire and other cookies-related settings

    Your profile properties are compiled as part of the top-level items compilation - AKA Compilation Life-Cycle in ASP.Net, therefore they will be exposed as strongly-typed properties through the Profile class

    For example:

    Web.config settings

    
      
        
        
          
            
            
            
            
              
              
              
            
            
          
        
      
    
    

    Consuming the profile in code (Global.asax for this example)

    void Application_EndRequest(object sender, EventArgs e)
    {
        if (Profile != null)
        {
            Profile.LastVisit = DateTime.Now;
            Profile.Save();
        }
    }
    

    Additionally, ASP.Net lets you access the properties in JavaScript, using Microsoft AJAX components:

    Web.config

    
      
        
          
            
            
          
        
      
    
    

    ASPX

    
    
    
    
        
        
        
    
    

    0 讨论(0)
提交回复
热议问题