none
重写的方法总提示错误,自己看不出那里没实现,求教 RRS feed

  • 问题

  • public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out MembershipCreateStatus status)
            {
                //throw new NotImplementedException();
                //判断以下过程
                try
                {
                    //判断email是否格式正确
                    if(string .IsNullOrEmpty(email))
                    throw new MembershipCreateUserException (MembershipCreateStatus.InvalidEmail);
                    //判断username是否存在
                    if(GetUser(username,false)!= null)
                    throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
    
                    Users newUser = new Users
                    {
                        Username = username,
                        Password = password,
                        Email = email,
                        PasswordQuestion = passwordQuestion,
                        PasswordAnswer = passwordAnswer,
                        IsApproved = true,
                        IsLockedOut = false,
                        CreateDate = DateTime.Now,
                        Account_type = (int)1,
                        Isdisabled = false,
                    };
                    status = MembershipCreateStatus.Success;
                    
                }
    错误 2 “snwawa.Web.Providers.SnMembershipProvider.CreateUser(string, string, string, string, string, bool, out System.Web.Security.MembershipCreateStatus)”: 没有找到适合的方法来重写 E:\snwawa\snwawa\snwawa.Web\Providers\SnMembershipProvider.cs 105 40 snwawa.Web

    绝不不懂装懂,不因为自己的问题低级而感到不好意思,踏踏实实的虚心学习。

    2013年6月9日 18:27

全部回复

  • 我不清楚你重写哪个类,我反射看到的代码函数原型:

    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)


    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月10日 5:39
  • 你好,如 ProgrammingVolunter所說,你的Method缺少了 ProviderUserKey的parameter,請加進回。謝謝

    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    2013年6月10日 6:18
  •  按照您的指点,我重写了该方法

    public class SnMembershipProvider : MembershipProvider
        {

    //仅展现相关部分

    public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { //throw new NotImplementedException(); //判断以下过程 try { //判断email是否格式正确 if(string .IsNullOrEmpty(email)) throw new MembershipCreateUserException (MembershipCreateStatus.InvalidEmail); //判断username是否存在 if(GetUser(username,false)!= null) throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName); Users newUser = new Users { Username = username, Password = password, Email = email, PasswordQuestion = passwordQuestion, PasswordAnswer = passwordAnswer, IsApproved = true, IsLockedOut = false, CreateDate = DateTime.Now, Account_type = (int)1, Isdisabled = false, }; status = MembershipCreateStatus.Success; } catch (MembershipCreateUserException ex) { status = ex.StatusCode; } catch (Exception) { status = MembershipCreateStatus.ProviderError; } return null; }

    }

    但是关于ProviderUserKey 因为我自定义的数据库中没有这个列  所以我不想要这个参数 或者说该参数对我无意义  重写的时候 我应该如何处理这个参数。

    另外我在注册页面用的为

    MembershipUser newUser = Membership.CreateUser(UsernameTextBox.Text, PasswordTextBox.Text, EmailTextBox.Text, PasswordQuestionTextBox.Text, PasswordAnswerTextBox.Text, true, out status);
     
     if (newUser == null)
                     {
                         zhucebaogao.Text = createusercuowu(status);
                     }
                     else 
                    {
                         Response.Redirect("");
                     }
                 }
                 catch 
                {
                     zhucebaogao.Text = "亲,对不起,创建用户过程中发生意外,请联系管理员。";
                 }
             }
    

    结果错误信息提示我创建用户过程中发生意外,  这具体是哪里的错误,我该如何做。


    绝不不懂装懂,不因为自己的问题低级而感到不好意思,踏踏实实的虚心学习。




    • 已编辑 沉默种子 2013年6月19日 16:56 完善问题
    2013年6月19日 16:02
  • @但是关于ProviderUserKey 因为我自定义的数据库中没有这个列  所以我不想要这个参数 或者说该参数对我无意义  重写的时候 我应该如何处理这个参数。

    必须保留,否则无法重载。

    @结果错误信息提示我创建用户过程中发生意外

    具体异常?


    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月20日 7:48
  • 不知道为什么之前还能下载,但后来无法下载了,特此修改:把相关的文件都发布上来

    web.config文件内容:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      有关如何配置 ASP.NET 应用程序的详细信息,请访问
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="DomainServiceModule" preCondition="managedHandler"
            type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
      </system.webServer>
      
      
      
      
      <!--数据库连接-->
      <connectionStrings>
        <add name="snwawagame.Web.Properties.Settings.DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\snwawagame.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <system.web>
        <httpModules>
          <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </httpModules>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        
        
        
        
        <!--身份验证方式-->
        <authentication mode="Forms" />
        
        
        
        
        <!--成员资格提供-->
        <membership defaultProvider="sqlProvider" userIsOnlineTimeWindow="15">
          <providers>
            <clear />
            <add name="SqlProvider" 
                 type="System.Web.Security.SqlMembershipProvider" 
                 connectionStringName="snwawagame.Web.Properties.Settings.DefaultConnection"              
                 applicationName="snwawaApp"
                 connectionProtection="Secure"
                 enablePasswordRetrieval="false" 
                 enablePasswordReset="true"
                 maxInvalidPasswordAttempts="5"
                 minRequiredNonalphanumericCharacters="0"
                 minRequiredPasswordLength="8"
                 passwordAnswerAttemptLockoutDuration="30"
                 passwordAttemptWindow="10"
                 requiresQuestionAndAnswer="true" 
                 requiresUniqueEmail="False"             
                 passwordFormat="Hashed" />
            <!--name="SqlProvider"                                                                成员提供程序的名称
                type="System.Web.Security.SqlMembershipProvider"                                  成员资格提供程序的类型
                connectionStringName="snwawagame.Web.Properties.Settings.DefaultConnection"       成员资格程序提供的数据库连接
                applicationName="snwawaApp"                                                       数据库中记录的应用程序名称
                connectionProtection="Secure"                                                     传输层安全性
                enablePasswordRetrieval="false"                                                   是否支持密码检索
                enablePasswordReset="true"                                                        是否支持密码重置
                maxInvalidPasswordAttempts="5"                                                    提示问题答案尝试的次数
                minRequiredNonalphanumericCharacters="0"                                          密码中必须包含的特殊字符的最小数量
                minRequiredPasswordLength="8"                                                     密码中必需包含的字符的最小数量。
                passwordAnswerAttemptLockoutDuration="30"                                         密码提示问题答案后被锁定的时间长度
                passwordAttemptWindow="10"                                                        连续尝试次数的时间长度 超过10分钟为第一次
                requiresQuestionAndAnswer="true"                                                  是否需要密码提示问题答案才允许进行密码重置和检索            
                requiresUniqueEmail="False"                                                       电子邮件地址是否必须是唯一的
                passwordFormat="Hashed"                                                           密码加密格式-->
          </providers>       
        </membership>
      </system.web>
      
      
      
      
      
      <!--实体连接框架-->
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    </configuration>


    绝不不懂装懂,不因为自己的问题低级而感到不好意思,踏踏实实的虚心学习。

    2013年6月26日 13:47
  • 重写的SnMembershipProvider

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.Configuration;
    using System.Configuration;
    
    namespace snwawagame.Web.Providers
    {
        public class SnMembershipProvider : MembershipProvider
        {
            //定义成员资格参数
            //private int newPasswordLength = 8;
            //private string applicationName = "snwawaApp";
            
    
            //获取web.config中的设置
            //设置配置文件路径
            static string configPath = "";        
            //取得web应用程序设置对象
            static Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
             MembershipSection configSection = (MembershipSection)config.GetSection("system.web/membership");
            
    
            //实现属性 应用程序名称
            public override string ApplicationName
            {
                get
                {
                    throw new NotImplementedException();
                }
                set
                {
                    throw new NotImplementedException();
                }
            }
    
            //实现属性 密码重置
            public override bool EnablePasswordReset
            {
                get { throw new NotImplementedException(); }
            }
    
            //实现属性 密码取回
            public override bool EnablePasswordRetrieval
            {
                get { throw new NotImplementedException(); }
            }
            //设置密码错误尝试次数
            public override int MaxInvalidPasswordAttempts
            {
                get { throw new NotImplementedException(); }
            }
            //设置密码最小特殊符个数
            public override int MinRequiredNonAlphanumericCharacters
            {
                get { throw new NotImplementedException(); }
            }
            //设置密码字符个数
            public override int MinRequiredPasswordLength
            {
                get { throw new NotImplementedException(); }
            }
            //设置密码错误尝试间隔时间数
            public override int PasswordAttemptWindow
            {
                get { throw new NotImplementedException(); }
            }
            //设置密码加密方式
            public override MembershipPasswordFormat PasswordFormat
            {
                get { throw new NotImplementedException(); }
            }
            //设置计算密码的正则表达式
            public override string PasswordStrengthRegularExpression
            {
                get { throw new NotImplementedException(); }
            }
            //设置是否允许问题找回或重置密码
            public override bool RequiresQuestionAndAnswer
            {
                get { throw new NotImplementedException(); }
            }
            //设置是否电子邮件为唯一值
            public override bool RequiresUniqueEmail
            {
                get { throw new NotImplementedException(); }
            }
            //重写修改密码
            public override bool ChangePassword(string username, string oldPassword, string newPassword)
            {
                throw new NotImplementedException();
            }
            //重写修改密码问题和答案
            public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
            {
                throw new NotImplementedException();
            }
    
    
            //以下为方法
    
            //重写添加用户
            public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
            {
                //throw new NotImplementedException();
                //判断以下过程
                try
                {
                    //判断email是否格式正确
                    if(string .IsNullOrEmpty(email))
                    throw new MembershipCreateUserException (MembershipCreateStatus.InvalidEmail);
                    //判断username是否存在
                    if(GetUser(username,false)!= null)
                    throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);
    
                    Users newUser = new Users
                    {
                        Username = username,
                        Password = password,
                        Email = email,
                        PasswordQuestion = passwordQuestion,
                        PasswordAnswer = passwordAnswer,
                        IsApproved = true,
                        IsLockedOut = false,
                        CreateDate = DateTime.Now,
                        Account_type = (int)1,
                        Isdisabled = false,
    
                    };
                    status = MembershipCreateStatus.Success;
                    
                }
                catch (MembershipCreateUserException ex)
                {
                    status = ex.StatusCode;
                }
                catch (Exception)
                {
                    status = MembershipCreateStatus.ProviderError;
                }
                return null;
            }
            //重写删除用户
            public override bool DeleteUser(string username, bool deleteAllRelatedData)
            {
                throw new NotImplementedException();
            }
           //重写按email查找用户
            public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
            {
                throw new NotImplementedException();
            }
            //重写按用户名查找用户
            public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
            {
                throw new NotImplementedException();
            }
            //重写获取所有用户
            public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
            {
                throw new NotImplementedException();
            }
            //重写获取当前访问的用户数
            public override int GetNumberOfUsersOnline()
            {
                throw new NotImplementedException();
            }
            //重写获取指定用户名的密码
            public override string GetPassword(string username, string answer)
            {
                throw new NotImplementedException();
            }
            //重写按用户名获取某用户的信息及时间签
            public override MembershipUser GetUser(string username, bool userIsOnline)
            {
                throw new NotImplementedException();
            }
            //重写获取按唯一标示获取某用户的信息及时间签
            public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
            {
                throw new NotImplementedException();
            }
            //重写获取指定电子邮件关联的用户名
            public override string GetUserNameByEmail(string email)
            {
                throw new NotImplementedException();
            }
            //重写自动重置某用户的密码为新密码
            public override string ResetPassword(string username, string answer)
            {
                throw new NotImplementedException();
            }
            //重写解锁用户
            public override bool UnlockUser(string userName)
            {
                throw new NotImplementedException();
            }
            //重写更新用户信息
            public override void UpdateUser(MembershipUser user)
            {
                throw new NotImplementedException();
            }
            //重写验证用户登陆
            public override bool ValidateUser(string username, string password)
            {
                throw new NotImplementedException();
            }
        }
    }


    绝不不懂装懂,不因为自己的问题低级而感到不好意思,踏踏实实的虚心学习。

    2013年6月26日 13:52
  • 注册页面中 注册按钮调用的方法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Security;
    
    namespace snwawagame.Web.web
    {
        public partial class zhuce : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void CreateUserButton_Click(object sender, EventArgs e)
            {
                //定义创建用户成败信息
                MembershipCreateStatus status;
                try
                {
                    MembershipUser newUser = Membership.CreateUser(UsernameTextBox.Text, PasswordTextBox.Text, EmailTextBox.Text, PasswordQuestionTextBox.Text, PasswordAnswerTextBox.Text, true, out status);
                    //
                    if (newUser == null)
                    {
                        zhucebaogao.Text = createusercuowu(status);
                    }
                    else 
                    {
                        Response.Redirect("");
                    }
                }
                catch
                {
                    zhucebaogao.Text = "亲,对不起,创建用户过程中发生意外,请联系管理员。";
                }
                
            }
    
            //把注册用户中Membershipcreatstaus返回的错误中文化
            private string  createusercuowu(MembershipCreateStatus status)
            {
                switch (status)
                {
                    case MembershipCreateStatus.DuplicateUserName:
                        return "亲,对不起,用户名已经存在,请输入一个新的用户名。";
    
                    case MembershipCreateStatus.DuplicateEmail:
                        return "亲,对不起,该电子邮件地址已经存在的用户名。请输入一个不同的电子邮件地址。";
    
                    case MembershipCreateStatus.InvalidPassword:
                        return "亲,对不起,提供的密码无效。请输入有效的密码值。";
    
                    case MembershipCreateStatus.InvalidEmail:
                        return "亲,对不起,提供的电子邮件地址无效。请检查电子邮件地址,然后重试。";
    
                    case MembershipCreateStatus.InvalidAnswer:
                        return "亲,对不起,提供的密码恢复答案是无效的。请检查密码恢复答案,然后重试。";
    
                    case MembershipCreateStatus.InvalidQuestion:
                        return "亲,对不起,提供的密码恢复问题是无效的。请检查密码恢复问题,然后重试。";
    
                    case MembershipCreateStatus.InvalidUserName:
                        return "亲,对不起,提供的用户名称无效。请检查用户名,然后重试。";
    
                    case MembershipCreateStatus.ProviderError:
                        return "亲,对不起,请确认您的输入并再试一次。如果问题仍然存在,请联系您的系统管理员。";
    
                    case MembershipCreateStatus.UserRejected:
                        return "用户创建的请求已被取消。请确认您的输入并再试一次。如果问题仍然存在,请联系您的系统管理员。";
    
                    default:
                        return "亲,对不起,系统总觉得好像什么地方出错了。请确认您的输入并再试一次。如果问题仍然存在,请联系您的系统管理员。";
                }
    
            }
        }
    }


    绝不不懂装懂,不因为自己的问题低级而感到不好意思,踏踏实实的虚心学习。

    2013年6月26日 13:54
  • 按说自定义成员管理微软资料中相关的就这些文件 我也对比修改了,但是不能正常运行,请高手指点下,我哪里错了,应该如何修改。谢谢

    绝不不懂装懂,不因为自己的问题低级而感到不好意思,踏踏实实的虚心学习。

    2013年6月26日 13:56