如何配置成员船比ASPNETDB其他数据库 [英] How to configure member ship with a database other than aspnetdb

查看:94
本文介绍了如何配置成员船比ASPNETDB其他数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个数据库和表来存储用户登录的价值观和凭据。
asp.net是提供 aspnet_regsql 工具来创建成员资格相关活动的数据库。但我不想使用它。这就是为什么我创建另一个数据库。现在我想这个数据库连接到我的项目。我在web.config文件改变了的ConnectionString参数来我的新创建的数据库。但我无法登录。它给以下错误消息。

I created one database and tables to store the user login values and credentials. asp.net is providing aspnet_regsql tool to create a database for the membership related activities. But I dont want to use it. Thats why I created another database. Now I want to connect this database to my project. I changed in web.config file for the connectionstring parameter to my newly created database. But I am unable to login. It is giving following error message.

找不到存储过程'dbo.aspnet_CheckSchemaVersion

如何使用这项工作。有没有一步一步的程序有!如果有,请提供。
是否有任何事情来改变,而不是在web.config文件?

How to work with this. Is there any step by step procedures are there!! If so please provide. Is there any thing to change rather than the connection string in the web.config file?

推荐答案

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

You need to create a membership provider to connect to your custom tables for authentication. MSDN has some documentation on the subject. You can also view a video on the subject at ASP.NET. Here are the links.

  • http://msdn.microsoft.com/en-us/library/f1kyba5e(v=vs.100).aspx
  • http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-custom-membership-provider

有关验证的主要方法将是ValidateUser方法,你会重写此方法来提供身份验证。

The main method for validation is going to be the ValidateUser method, you will override this method to provide authentication.

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
}

如果您在您的应用程序角色,你可能还需要实现自定义角色提供程序:

If you have roles in your application you may also want to implement a custom role provider:

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

这篇关于如何配置成员船比ASPNETDB其他数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆