【问题标题】:How to configure member ship with a database other than aspnetdb如何使用除 aspnetdb 之外的数据库配置成员船
【发布时间】:2013-01-14 07:17:22
【问题描述】:

我创建了一个数据库和表来存储用户登录值和凭据。 asp.net 提供aspnet_regsql 工具来为会员相关活动创建数据库。但我不想使用它。这就是我创建另一个数据库的原因。现在我想将此数据库连接到我的项目。我在 web.config 文件中将 connectionstring 参数更改为我新创建的数据库。但我无法登录。它给出以下错误消息。

Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'

如何使用它。有没有分步程序啊!!如果有,请提供。 除了web.config文件中的连接字符串,还有什么要改变的吗?

【问题讨论】:

    标签: asp.net sql-server-2008 asp.net-membership


    【解决方案1】:

    您需要创建一个成员资格提供程序以连接到您的自定义表以进行身份​​验证。 MSDN 有一些关于这个主题的文档。您还可以在 ASP.NET 上观看有关该主题的视频。这是链接。

    验证的主要方法将是 ValidateUser 方法,您将覆盖此方法以提供身份验证。

    public sealed class CustomMembershipProvider : MembershipProvider
    {
        // implement other methods
    
        public override bool ValidateUser(string username, string password)
        {
            try
            {
                var user = // GET USER OBJECT HERE
                if (user != null)
                {
                    string name =  // set username
    
                    // Set your forms authentication ticket
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.ID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), false, name, FormsAuthentication.FormsCookiePath);
    
                    HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                    HttpContext.Current.Response.Cookies.Add(authCookie); 
                    return true;                    
                }
            }
            catch
            {
            }
    
            return false;
        }
    
        // Other implementations
    }
    

    如果您的应用程序中有角色,您可能还希望实现自定义角色提供程序:

    http://msdn.microsoft.com/en-us/library/8fw7xh74(v=vs.100).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 2020-05-30
      相关资源
      最近更新 更多