为什么使用告诉.net有关提供程序的信息? [英] Why using telling .net about provider?

查看:80
本文介绍了为什么使用告诉.net有关提供程序的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么很多人谈论创建从asp.net库中的某个基类继承的成员资格提供程序,并在web.config文件中注册该提供程序.因为我们无需这样做就能得到我们想要的任何东西.我编写了一个静态类,可以检查用户是否存在相应的数据库,添加用户,通过调用FormsAuthentication.SetAuthCookie验证用户身份,然后一切正常.很快,为什么我们需要告诉web.config文件我们使用哪个提供程序.为什么我们的提供商需要继承成员资格提供商?

I can't understand why many people talk about creating membership provider that inherit from some base class in the asp.net library and registering the provider in the web.config file. Because we can get anything we want without doing this. I have written a static class that can check if a user exists with a corresponding database, add users, authenticate users by calling FormsAuthentication.SetAuthCookie and everything works. Shortly, Why we need to tell web.config file which provider we use. Why Our provider need to inherit Membership Provider ?

推荐答案

为什么我们需要告诉web.config文件我们使用哪个提供程序.

Why we need to tell web.config file which provider we use.

因为这就是提供程序模型在ASP.NET中的工作方式.如果编写自定义提供程序,则需要在web.config中注册它.您还需要指出哪个是您的应用程序将使用的默认提供程序.角色提供者也是如此.

Because that's how the provider model works in ASP.NET. If you write a custom provider you need to register it in web.config. You also need to indicate which is the default provider that your application will use. The same is true for the Role provider as well.

我们的提供商需要继承成员资格提供商吗?

Our provider need to inherit Membership Provider ?

否,您不需要这样做.您可能具有完全自定义的代码,该代码将执行成员资格提供程序的任务,例如验证用户的凭据或创建新用户.

No, you are not required to do that. You could have a completely custom code that will perform the tasks of a membership provider such as verifying the credentials of a user or creating a new user.

成员资格提供者只是大多数开发人员都熟悉的在ASP.NET应用程序中执行这些任务的标准方法.如果您决定使用自己的自定义代码,那么如果有新开发人员加入您的团队,他将需要了解所有这些自定义代码.

The membership provider is just a standard way of performing those tasks in ASP.NET applications that most developers are familiar with. If you decide to roll your own custom code then if a new developer joins your team he will need to learn about all this custom code.

您还提到您编写了一个静态类.静态类用于此类事情的缺点是,您将应用程序的不同层紧密耦合在一起,因此很难单独测试和重用它们.成员资格提供者的全部要点是它是一种抽象.同样,如果您不需要所有功能,则在编写自定义成员资格提供程序时不需要覆盖所有方法.仅那些您实际使用的.

Also you mentioned that you wrote a static class. The drawback of static classes for those kind of things is that you are strongly coupling the different layers of your application making it difficult to test and reuse them in isolation. The whole point of the membership provider is that it is an abstraction. Also if you do not need all the functionality you don't need to override all the methods when writing a custom membership provider. Only those that you are actually using.

这篇关于为什么使用告诉.net有关提供程序的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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