2012-03-22 51 views
1

我的网站上,当用户登录创建一个会话对象具有以下属性我应该在会话中存储用户数据还是使用自定义配置文件提供程序?

DisplayName, 
Email, 
MemberId 

问题

  1. 会使其使用自定义配置文件提供用于保存用户 数据更有意义?
  2. 什么是每种方法(会话和自定义配置文件提供程序)的专业版和控制台?
  3. 使用自定义提供程序为 可以来自一个或多个表的只读数据是否有意义?
+0

我不明白你的问题:当用户放弃或闲置20分钟时,会话过期。如果您需要持久保存数据,则可以使用.Net Profile将这些信息存储在数据库中。 – enricoariel 2012-03-23 09:01:15

+0

我不确定你不明白 – chobo 2012-03-23 15:38:52

回答

2

我的回答并不是直接针对你的问题。这只是一种替代方法。

我创建自定义上下文来跟踪当前登录用户的配置文件,而不是自定义配置文件提供程序。这里是示例代码。您可以将DisplayName,Email,MemberId替换为MyUser类。

void Application_AuthenticateRequest(object sender, EventArgs e) 
{ 
    if (HttpContext.Current.User != null && 
     HttpContext.Current.User.Identity.IsAuthenticated) 
    { 
     MyContext.Current.MyUser = YOURCODE.GetUserByUsername(HttpContext.Current.User.Identity.Name); 
    } 
} 

public class MyContext 
{ 
    private MyUser _myUser; 

    public static MyContext Current 
    { 
     get 
     { 
      if (HttpContext.Current.Items["MyContext"] == null) 
      { 
       MyContext context = new MyContext(); 
       HttpContext.Current.Items.Add("MyContext", context); 
       return context; 
      } 
      return (MyContext) HttpContext.Current.Items["MyContext"]; 
     } 
     } 

     public MyUser MyUser 
     { 

      get { return _myUser; } 
      set { _myUser = value; } 
     } 
    } 
} 
相关问题