本帖最后由 ilearn 于 2014-09-04 22:46:20 编辑

解决方案 »

  1.   

    后来我改写成这样,不知道行不行?需不需要配置什么的?
     string connstr = "server =XXX;database=XX;uid=sa;pwd=";
                try
                {
                     using (DataClasses1DataContext  db = new DataClasses1DataContext(connstr))
                     {
                         int thecount=(from c in db.web_myuser 
                                        where c.username==imodel.user && c.passwrd ==imodel.pass
                                           select c).Count();
                         if (thecount == 0)
                         {
                             logerr("创建用户", "密码不对");
                             return -1;
                         }
                                                  RegisterBindingModel rbmodel = new RegisterBindingModel();
                         rbmodel.Email = imodel.email;
                         rbmodel.Password = imodel.passapply;
                         rbmodel.ConfirmPassword = imodel.passapply;
                         if (ModelState.IsValid)
                         {
                             // Attempt to register the user
                             try
                             {
                                 WebSecurity.CreateUserAndAccount(
                                     imodel.userapply ,
                                     imodel.passapply ,
                                     new { Email = imodel.email },
                                     false);                             WebSecurity.Login(imodel.userapply, imodel.passapply);
                                 return 0;
                                 
                             }
                             catch (MembershipCreateUserException e)
                             {
                                 string expmessag = e.ToString();
                                if (expmessag.Length > 900)
                                 expmessag = e.ToString().Substring(0, 900);
                                 logerr("创建用户", expmessag);
                                 return -3;
                             }
                         }
                         else
                         {
                             return -5;
                         }
                     }            }
                catch(Exception e)
                {
                    string expmessag = e.ToString();
                    if (expmessag.Length > 900)
                        expmessag = e.ToString().Substring(0, 900);
                    logerr("创建用户", expmessag);
                    return -2;
                }
                
            }