使用 WebMatrix.WebData.WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
                                                                   new
                                                                       {
                                                                           Email = model.UserName,
                                                                           model.NickName,
                                                                           model.Sex,
                                                                           model.Province,
                                                                           model.City,
                                                                           model.ProvinceName,
                                                                           model.CityName,
                                                                           RegIp = Dev.Comm.Web.HostHelper.getRealIp()
                                                                       }, true);

 

创建用户,在数据库中记录不是当前时区的时间,记录的 UTC 时间 (http://zh.wikipedia.org/zh/%E5%8D%8F%E8%B0%83%E4%B8%96%E7%95%8C%E6%97%B6),所以这SB玩意记录的是0时区的的时间, 在取出后,所以与当前时间差8小时, 北京时间为+8时区。

 

 

 

下面反编后的代码片断。

 

// WebMatrix.WebData.SimpleMembershipProvider
/// <summary>Creates a new user account by using the specified user name and password.</summary>
/// <returns>A token that can be sent to the user to confirm the user account.</returns>
/// <param name="userName">The user name.</param>
/// <param name="password">The password.</param>
/// <param name="requireConfirmationToken">(Optional) true to specify that the user account must be confirmed; otherwise, false. The default is false.</param>
/// <exception cref="T:System.Web.Security.MembershipCreateUserException">
///   <paramref name="username" /> is empty.-or-<paramref name="username" /> already has a user account.-or-<paramref name="password" /> is empty.-or-<paramref name="password" /> is longer than 128 characters.-or-A user record that corresponds to <paramref name="username" /> does not exist in the <see cref="P:WebMatrix.WebData.SimpleMembershipProvider.UserTableName" /> table (the user profile table).-or-The database operation failed.</exception>
/// <exception cref="T:System.InvalidOperationException">The <see cref="T:WebMatrix.WebData.SimpleMembershipProvider" /> class was not initialized using a call to the <see cref="Overload:WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection" /> method.</exception>
public override string CreateAccount(string userName, string password, bool requireConfirmationToken)
{
    this.VerifyInitialized();
    if (password.IsEmpty())
    {
        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
    }
    string text = Crypto.HashPassword(password);
    if (text.Length > 128)
    {
        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword);
    }
    if (userName.IsEmpty())
    {
        throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName);
    }
    string result;
    using (IDatabase database = this.ConnectToDatabase())
    {
        int userId = SimpleMembershipProvider.GetUserId(database, this.SafeUserTableName, this.SafeUserNameColumn, this.SafeUserIdColumn, userName);
        if (userId == -1)
        {
            throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError);
        }
        object arg = database.QuerySingle("SELECT COUNT(*) FROM [" + SimpleMembershipProvider.MembershipTableName + "] WHERE UserId = @0", new object[]
        {
            userId
        });
        if (SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site23 == null)
        {
            SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site23 = CallSite<Func<CallSite, object, bool>>.Create(Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsTrue, typeof(SimpleMembershipProvider), new CSharpArgumentInfo[]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
            }));
        }
        Func<CallSite, object, bool> arg_191_0 = SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site23.Target;
        CallSite arg_191_1 = SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site23;
        if (SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site24 == null)
        {
            SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site24 = CallSite<Func<CallSite, object, int, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.GreaterThan, typeof(SimpleMembershipProvider), new CSharpArgumentInfo[]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
            }));
        }
        Func<CallSite, object, int, object> arg_18C_0 = SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site24.Target;
        CallSite arg_18C_1 = SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site24;
        if (SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site25 == null)
        {
            SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site25 = CallSite<Func<CallSite, object, int, object>>.Create(Binder.GetIndex(CSharpBinderFlags.None, typeof(SimpleMembershipProvider), new CSharpArgumentInfo[]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
            }));
        }
        if (arg_191_0(arg_191_1, arg_18C_0(arg_18C_1, SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site25.Target(SimpleMembershipProvider.<CreateAccount>o__SiteContainer22.<>p__Site25, arg, 0), 0)))
        {
            throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
        }
        string text2 = null;
        object obj = DBNull.Value;
        if (requireConfirmationToken)
        {
            text2 = SimpleMembershipProvider.GenerateToken();
            obj = text2;
        }
        int num = 0;
        int num2 = database.Execute("INSERT INTO [" + SimpleMembershipProvider.MembershipTableName + "] (UserId, [Password], PasswordSalt, IsConfirmed, ConfirmationToken, CreateDate, PasswordChangedDate, PasswordFailuresSinceLastSuccess) VALUES (@0, @1, @2, @3, @4, @5, @5, @6)", new object[]
        {
            userId,
            text,
            string.Empty,
            !requireConfirmationToken,
            obj,
            DateTime.UtcNow,
            num
        });
        if (num2 != 1)
        {
            throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError);
        }
        result = text2;
    }
    return result;
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

解决方案:

  /// <summary>
        /// 将UTC 时间 转化为本地化时间
        /// </summary>
        /// <param name="utcDate"></param>
        /// <returns></returns>
        public static DateTime UtcToLocal(DateTime utcDate)
        {
            DateTime convertedDate = DateTime.SpecifyKind(utcDate, DateTimeKind.Utc);
 
            var localtime = convertedDate.ToLocalTime();
 
            return localtime;
        }
 
// TEST
[TestClass]
    public class DateUtilTest
    {
        [TestMethod]
        public void UtcToLocal()
        {
            var UtcDate = new DateTime(2013, 1, 1, 1, 1, 1);
 
            DateTime converted = DateUtil.UtcToLocal(UtcDate);
            Assert.AreEqual(UtcDate.AddHours(8), converted);
 
        }
    }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

 

已经更新至 https://github.com/zbw911/Dev.All/tree/master/DLL%20Release 最新dll

关于 SimpleMembership 中 CreateDate 的问题的更多相关文章

  1. SimpleMembership

    最近2个月以来,一直在学习MVC,从最开始的2,一直到最新的4.从原来的aspx到现在的Razor引擎,越学越开心,越学越上瘾. 最近为新项目做准备,打算用MVC4,VS2012+SQL2012,反正 ...

  2. SQL 分组后获取其中一个字段最大值的整条记录

    --有id,name,createDate的一张表testTable--根据name分组,获取每组中createDate最大的那条记录(整条)查询出来------------------------- ...

  3. EF-CodeFirst系列100

    .学习资料地址: CodeFirst:https://msdn.microsoft.com/zh-cn/data/jj193542 一.CodeFirst迁移(Migration) .工具--> ...

  4. MongoDB Index

    索引通常能够极大的提高查询的效率,如果没有索引,MongoDB在读取数据时必须扫描集合中的每个文件并选取那些符合查询条件的记录. 这种扫描全集合的查询效率是非常低的,特别在处理大量的数据时,查询可以要 ...

  5. MongoDB 基础知识学习笔记

    注意:本文假设您已经安装好 MongoDB 数据库并启动它了. 连接 MongoDB.数据库操作.集合操作 连接 MongoDB mongo ip:port/dbName -u username -p ...

  6. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

  7. [转]ThinkPHP中实例化对象M()和D()的区别,select和find的区别

    1.ThinkPHP中实例化对象M()和D()的区别 在实例化的过程中,经常使用D方法和M方法,这两个方法的区别在于M方法实例化模型无需用户为每个数据表定义模型类,如果D方法没有找到定义的模型类,则会 ...

  8. 关于mybatis中mapper.xmlSQL语句书写的心得

    本文主要针对MySQL ---------------------------------------------------------------------------------------- ...

  9. 大数据系列-CDH环境中SOLR入数据

    1       创建集合 SSH远程连接到安装了SOLR的CDH节点. 运行solrctl  instancedir  --generate  /solr/test/GX_SH_TL_TGRYXX_2 ...

随机推荐

  1. Android studio如何和VS的region一样折叠代码

    相信用过VS的朋友都会经常有用到VS的region来折叠代码,非常方便.那么Android studio是否可以呢?当然可以. 选择代码,Ctrl + Alt + T 选择 第二项,这样就可以啦

  2. 【原】Coursera—Andrew Ng机器学习—Week 3 习题—Logistic Regression 逻辑回归

    课上习题 [1]线性回归 Answer: D A 特征缩放不起作用,B for all 不对,C zero error不对 [2]概率 Answer:A [3]预测图形 Answer:A 5 - x1 ...

  3. Vue基础以及指令, Vue组件

    Vue基础篇一 Vue指令 Vue的指令directive很像我们所说的自定义属性,指令时Vue模板中最常用的功能,它带有v-前缀,功能是当表达式改变的时候,相应的行为作用在DOM上. <div ...

  4. os.chdir("/deepmatching") OSError: [Errno 2] No such file or directory: '/deepmatching'

    #os.chdir("/deepmatching")os.chdir(os.path.dirname(os.path.abspath("deepmatching1&quo ...

  5. 18-拍卖叫价(hdu2149 巴什博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=2149 Public Sale Time Limit: 1000/1000 MS (Java/Others)    ...

  6. 使用mail架包发送邮件javax.mail.AuthenticationFailedException: failed to connect at javax.mail.Service.connec

    这个错误是因为连接不上邮箱服务器导致的,可能有以下几个原因(以网易邮箱为例) 1.当使用第三方登录邮箱时需要有邮箱的授权码,且要开启POP3/SMTP/IMAP:服务 2.在代码中要调用网易邮箱的密码 ...

  7. 3.SELECT 语句

    SELECT 语句用于从表中选取数据. 结果被存储在一个结果表中(称为结果集). SQL SELECT 语法 SELECT 列名称 FROM 表名称 以及: SELECT * FROM 表名称 注释: ...

  8. Django框架 之 查询 Extra

    Django框架 之 查询 Extra extra 1 2 extra(select=None, where=None, params=None,       tables=None, order_b ...

  9. storm源码分析之任务分配--task assignment

    在"storm源码分析之topology提交过程"一文最后,submitTopologyWithOpts函数调用了mk-assignments函数.该函数的主要功能就是进行topo ...

  10. MFC可视化

    当你修改了变量的值,而希望对话框控件更新显示,就应该在修改变量后调用UpdateData(FALSE):如果你希望知道用户在对话框中到底输入了什么,就应该在访问变量前调用UpdateData(TRUE ...