在dll中使用asp.net会员提供商 [英] using asp.net membership provider in a dll
问题描述
我正在一个DLL中建立这个DLL,它将与我们的内部网站现场。使这项工作最好的方法是什么?该DLL将不引用网络应用程序,网络应用程序将引用该DLL。如何使DLL感知会员提供商?
TIA
PS:如果已经回答其他地方请指示我...
编辑:我发现一篇关于在WinForms和/或WPF应用程序中使用ASP.NET成员身份的文章。不幸的是,这些依赖于app.config文件。一旦出现DLL似乎不使用app.config。如果我错了,请让我直线!文章在这里: http://aspalliance.com/1595_Client_Application_Services__Part_1.all
嗯,看来,设置SqlMembershipProvider的连接字符串的唯一方法是使用初始化方法,根据文档,不应该从我们的代码中调用。 / p>
使用ASP.NET应用程序的
中指定的属性值
初始化SQL Server成员资格
提供程序配置文件这个方法不是直接从
代码使用的
。
所以基本上我们必须一个方法来将该信息导入到与托管该DLL的应用程序相关联的配置文件中。
您所要做的只是参考系统。在程序集中的web.dll
和 system.configuration.dll
中,使用SqlMembershipProvider,然后在app.config中设置适当的值以执行像这样:
<?xml version =1.0encoding =utf-8?>
< configuration>
< connectionStrings>
< add name =MembershipConnectionStringconnectionString =connectionstringdetailsproviderName =System.Data.SqlClient/>
< / connectionStrings>
< system.web>
< membership defaultProvider =DefaultSqlMembershipProvider>
< providers>
< clear />
< add name =DefaultSqlMembershipProviderconnectionStringName =MembershipConnectionStringtype =System.Web.Security.SqlMembershipProvider/>
< / providers>
< / membership>
< /system.web>
< / configuration>
需要注意的是,如果您使用MyAssembly.dll和TheApp.exe这应该是TheApp.exe.config,而不是MyAssembly.dll.config。配置文件始终与执行程序集相关联。
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
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.
Initializes the SQL Server membership provider with the property values specified in the ASP.NET application's configuration file. This method is not intended to be used directly from your 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
and system.configuration.dll
in your assembly, use the SqlMembershipProvider, and then set the proper values in the app.config for executable like so:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="MembershipConnectionString" connectionString="connectionstringdetails" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<membership defaultProvider="DefaultSqlMembershipProvider">
<providers>
<clear />
<add name="DefaultSqlMembershipProvider" connectionStringName="MembershipConnectionString" type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
</system.web>
</configuration>
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.
这篇关于在dll中使用asp.net会员提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!