在dll中使用asp.net会员提供商 [英] using asp.net membership provider in a dll

查看:201
本文介绍了在dll中使用asp.net会员提供商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几年来,我已经在网络应用程序中使用过会员资格提供商。我现在有一个新的要求,用于工作中的内部项目。他们想要一个服务(而不是一个Web服务)来进行快速验证。基本上,显示 ValidateUser(UserName,Password)方法...



我正在一个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屋!

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