Using asp.net dll membership provider

I have used Membership Providers in web applications over the past few years. Now I have a new โ€œrequestโ€ for an internal project. They would like the service (not the web service) to perform fast authentication. Basically, exposing the ValidateUser (UserName, Password) method ...

I create this in a DLL that will sit with our internal website. What is the best approach to do this job? The DLL will not refer to the web application, but the web application will refer to the DLL. How can I report a membership provider dll?

TIA

PS: If it was answered elsewhere, direct me to this ...

EDIT: I found an article about using ASP.NET membership with WinForms and / or WPF applications. Unfortunately, they depend on the app.config file. The dll does not seem to use app.config after posting. If I'm wrong, put me straight! The article is here: http://aspalliance.com/1595_Client_Application_Services__Part_1.all

+1
source share
2 answers

Well, it seems that the only way to set the SqlMembershipProvider connection string is to use the Initialize method, which according to the documentation should not be called from our code.

Initializes membership in the SQL Server provider with the property values โ€‹โ€‹specified in the ASP.NET application configuration file. This method is not intended to be used directly.

So, basically, we need to figure out a way to get this information in the configuration file associated with the application in which the dll is located.

All you have to do is reference the system.web.dll and system.configuration.dll in your assembly, use SqlMembershipProvider and then set the correct values โ€‹โ€‹in app.config for the executable as follows:

 <?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> 

It is important to note that if you are "MyAssembly.dll" and "TheApp.exe", it should be "TheApp.exe.config" and not "MyAssembly.dll.config". The configuration file is always associated with the running assembly.

+1
source

On the website, when the application starts (Application_Start in global.asax), you can pass the link to the membership provider, which the website knows about the DLL that you wrote. The dll just expects the type System.Web.Security.MembershipProvider . Thus, the dll can still call the required method from the implementation, but does not know the type of the provider runtime at compile time (this is what is known as dependency injection).

0
source

Source: https://habr.com/ru/post/1334178/


All Articles