提供了自定义数据库功能来定制asp.net成员资格提供 [英] Providing custom database functionality to custom asp.net membership provider

查看:178
本文介绍了提供了自定义数据库功能来定制asp.net成员资格提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的asp.net应用程序创建自定义的成员提供。我还创建了一个单独的类数据库连接提供的数据库功能,如执行的SQL语句,执行的SP,执行SP或查询并返回SqlDataReader的等等...

I am creating custom membership provider for my asp.net application. I have also created a separate class "DBConnect" that provides database functionality such as Executing SQL statement, Executing SPs, Executing SPs or Query and returning SqlDataReader and so on...

我创建数据库连接类的实例在Global.asax中的在session_start并存储到一个会话。后来用我使用同样的单个会话整个应用程序提供数据库功能的静态类。总之,我提供任何asp.net页面所有数据库操作的单点。

I have created instance of DBConnect class within Session_Start of Global.asax and stored to a session. Later using a static class I am providing the database functionality throughout the application using the same single session. In short I am providing a single point for all database operations from any asp.net page.

我知道我可以写我自己的代码来连接/断开连接数据库,并执行SP的从方法中我需要重写。请看下面的代码 -

I know that i can write my own code to connect/disconnect database and execute SPs within from the methods i need to override. Please look at the code below -

public class SGI_MembershipProvider : MembershipProvider
{

......

    public override bool ChangePassword(string username, string oldPassword, string newPassword)
    {
        if (!ValidateUser(username, oldPassword))
            return false;

        ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true);

        OnValidatingPassword(args);

        if (args.Cancel)
        {
            if (args.FailureInformation != null)
            {
                throw args.FailureInformation;
            }
            else
            {
                throw new Exception("Change password canceled due to new password    validation failure.");
            }
        }

.....        

//Database connectivity and code execution to change password.

}

....

}

我的问题 -
现在我需要的是从同一个数据库点所有这些重写的方法中执行数据库一部分在上面描述。这是我必须通过数据库连接现有会话中的这个类的实例,以便我可以访问的方法。

MY PROBLEM - Now what i need is to execute the database part within all these overriden methods from the same database point as described on the top. That is i have to pass the instance of DBConnect existing in the session to this class, so that i can access the methods.

任何人都可以提供这方面的解决方案。可能有一些更好的技术,我不知道这一点。我使用的方法可能是错误的。你suggessions总是受欢迎的。

Could anyone provide solution on this. There might be some better techniques i am not aware of that. The approach i am using might be wrong. Your suggessions are always welcome.

感谢您分享您的宝贵时间。

Thanks for sharing your valuable time.

推荐答案

了解成员资格提供程序的生命周期将有助于清除此了。

Understanding the lifecycle of the membership provider would help clear this up.

成员资格提供程序的实例加速旋转时,在应用程序启动并为保持活动在<击>应用的AppDomain,这实际上等同于应用程序生命周期的寿命。例如如果由于某种原因在AppDomain周期,应用程序设置,并且一个新的实例起转。注册会员提供的一个新的实例纺了在第一次使用。

An instance of the membership provider is spun up when the application is started and remains active for the lifetime of the application AppDomain, which in practice equates to the application lifecycle. e.g. If for some reason the AppDomain cycles, the application is disposed and a new instance is spun up. A new instance of the registered membership provider is spun up on first use.

您需要在要么实例化您的数据访问类的的实例的您的会员提供者实现或访问从静态的 的提供商中的方法。我更喜欢使用一个实例。

You need to either instantiate an instance of you data access class within your membership provider implementation or access static methods from within your provider. I prefer to use an instance.

分离成员资格提供从它创建单身或应用程序积攒它的数据访问是在我看来,一个黑客攻击,并会导致什么,但痛苦,悲伤,失去的睡眠和信誉之中同行。

Separating the membership provider from it's data access by creating singletons or stashing it in application is a hack in my opinion and will lead to nothing but pain, sorrow, lost sleep and credibility amongst your peers.

干杯,祝你好运。

这篇关于提供了自定义数据库功能来定制asp.net成员资格提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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