在 dll 中使用 ASP.NET 会员资格提供程序
过去几年我在网络应用程序中使用了会员提供程序。我现在对工作中的内部项目有一个新的“请求”。他们希望有一个服务(而不是 Web 服务)来进行快速身份验证。基本上,公开 ValidateUser(UserName, Password) 方法...
我正在将其构建在一个 DLL 中,该 DLL 将与我们的内部网站一起使用。完成这项工作的最佳方法是什么?该 DLL 将不会引用 Web 应用程序,而 Web 应用程序将引用该 DLL。如何让 DLL 知道成员资格提供程序?
TIA
PS:如果这个问题已在其他地方得到解答,请指导我...
编辑:我找到了一篇有关在 WinForms 和/或 WPF 应用程序中使用 ASP.NET 会员资格的文章。不幸的是,这些依赖于 app.config 文件。 DLL 似乎在发布后不再使用 app.config。如果我错了,请纠正我!文章位于:http://aspalliance.com/1595_Client_Application_Services__Part_1.all
I've used Membership Providers in web apps over the last several years. I now have a new "request" for an internal project at work. They would like a service (not a web service) to do a quick authenticate against. Basically, exposing the ValidateUser(UserName, Password) method...
I am building this in a DLL that will sit with our internal web site. What is the best approach to make this work? The DLL will not reference the web app and the web app will reference the DLL. How do I make the DLL aware of the Membership Provider?
TIA
PS: If this has been answered elsewhere please direct me to that...
EDIT: I found an article on using ASP.NET Membership with WinForms and/or WPF applications. Unfortunately, these depend on an app.config file. A DLL appears to not use the app.config once published. If I am wrong, please set me straight! The article is here: http://aspalliance.com/1595_Client_Application_Services__Part_1.all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,看来设置 SqlMembershipProvider 连接字符串的唯一方法是使用 初始化方法,根据文档,不应从我们的代码中调用该方法。
因此,基本上我们必须找到一种方法将该信息放入与托管 dll 的应用程序关联的配置文件中。
您所要做的就是在程序集中引用
system.web.dll
和system.configuration.dll
,使用 SqlMembershipProvider,然后在应用程序中设置正确的值。可执行文件的配置如下:需要注意的重要一点是,如果您“MyAssembly.dll”和“TheApp.exe”,则应该是“TheApp.exe.config”,而不是“MyAssembly.dll.config”。配置文件始终与正在执行的程序集关联。
Well, it appears that the only way to set the connection string of a SqlMembershipProvider is to use the Initialize method, which according to the documentation, shouldn't be called from our code.
So basically we have to figure out a way to get that information into a config file associated with the application that's hosting the dll.
All you have to do is reference
system.web.dll
andsystem.configuration.dll
in your assembly, use the SqlMembershipProvider, and then set the proper values in the app.config for executable like so:The important thing to note is that if you "MyAssembly.dll" and "TheApp.exe", this should be "TheApp.exe.config", not "MyAssembly.dll.config". The config file is always associated with the executing assembly.
在网站中,当应用程序启动时(global.asax 中的Application_Start),您可以将网站识别的成员资格提供程序的引用传递给您编写的DLL。该 dll 只需要
System.Web.Security.MembershipProvider
类型。这样,dll 仍然可以从实现中调用所需的方法,但在编译时不知道提供程序的运行时类型(这就是所谓的依赖注入)。In the website, when the application starts (Application_Start in the global.asax), you can pass a reference of the membership provider that the website is aware of to the DLL you've written. The dll will simply expect the type
System.Web.Security.MembershipProvider
. This way the dll can still invoke the needed method from the implementation, but not know the runtime type of the provider at compile time (this is what is known as Dependency Injection).