I have two connecting string and two memebership default provider.
I just want to call the membership default provider when login page I select AD, then the page know how to connect to the ADmembershipprovider and when I select ACAD, then it’s will direct to the ACADmembershipprovider.
Please help. Thanks.
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://ad.fullerton.edu/DC=ad,DC=fullerton,DC=edu" />
<add name="ACADConnectionString" connectionString="LDAP://csufacad.fullerton.edu" />
<add connectionString="Data Source=hhdsrv02;Initial Catalog=DBHUSR; Integrated Security=True" name="DBHUSRConnectionString" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<membership defaultProvider="MyADMembershipProvider">
<providers>
<clear />
<add name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
attributeMapUsername="sAMAccountName" />
<add name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ACADConnectionString"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
</system.web>
Here is my login page code
<table>
<tr>
<td><p class="pad1"><u><asp:Label ID="Label2" runat="server" Text="Select Domain:"></asp:Label></u></p></td>
<td><p class="pad2"> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="DomainName" DataValueField="DomainName" Width="70px">
</asp:DropDownList></p></td>
</tr>
</table>
<asp:Label ID="Lblerror" runat="server" Text="Label"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DBHUSRConnectionString %>" SelectCommand="SELECT [DomainName] FROM [DomainName]"></asp:SqlDataSource>
<asp:Login ID="Login1" runat="server" DisplayRememberMe="False" Height="162px" Width="377px">
</asp:Login>
VB.Net code
Protected Sub Login1_LoggedIn(sender As Object, e As System.EventArgs) Handles Login1.LoggedIn
Dim connString As String = ConfigurationManager.ConnectionStrings("DBHUSRConnectionString").ConnectionString
Dim DBConnection As SqlConnection = New SqlConnection(connString)
Dim DBCommand As SqlCommand
Dim DBReader As SqlDataReader
Dim thisUserName As String
DBConnection.Open()
DBCommand = New SqlCommand("QGlobalUserRecords_sp", DBConnection)
DBCommand.CommandType = CommandType.StoredProcedure
DBCommand.Parameters.AddWithValue("@UserID", Login1.UserName())
DBReader = DBCommand.ExecuteReader()
Try
If DropDownList1.SelectedValue = "AD" Then
While DBReader.Read()
If Login1.UserName = DBReader("WM_UserName") Then
thisUserName = DBReader("WM_Comments")
Select Case thisUserName
Case "Agency"
Response.Redirect("~/Agency/Agency.aspx")
Case "Admins"
Response.Redirect("~/Admin/Default.aspx")
Case "STUHUSR"
Response.Redirect("~/Advising/StudentRecord.aspx")
Case "Faculty"
Response.Redirect("~/Faculty/Faculty.aspx")
End Select
End If
End While
End If
If DropDownList1.SelectedValue = "ACAD" Then
Response.Redirect("~/Student/StudentAssignment.aspx")
End If
Catch
Lblerror.Text = "Database connection error. Please try again."
Finally
DBConnection.Close()
End Try
End Sub